intraweb php,使用 IntraWeb (45) - 活用 IntraWeb

//在新建 IW 主窗体上放置 IWTemplateProcessorHTML1、IWLabel1 两个控件.

unit Unit1;

interface

uses

Classes, SysUtils, IWAppForm, IWApplication, IWColor, IWTypes, IWVCLComponent, IWBaseLayoutComponent, IWBaseContainerLayout, IWContainerLayout,

IWTemplateProcessorHTML, IWCompLabel, Vcl.Controls, IWVCLBaseControl, IWBaseControl, IWBaseHTMLControl, IWControl, IWCompButton, IWCompEdit;

type

TIWForm1 = class(TIWAppForm)

IWLabel1: TIWLabel;

IWTemplateProcessorHTML1: TIWTemplateProcessorHTML;

procedure IWAppFormCreate(Sender: TObject);

public

procedure DoCallBack1(EventParams: TStringList); //这是 IWForm1.js 将要调用的方法; 下面还需要通过 WebApplication.RegisterCallBack 注册一下

end;

implementation

{$R *.dfm}

uses IW.Common.AppInfo; //获取路径需要

var gPath: string;

procedure TIWForm1.IWAppFormCreate(Sender: TObject);

begin

LayoutMgr := IWTemplateProcessorHTML1; //关联模板(IWForm1.html)

IWTemplateProcessorHTML1.RenderStyles := False; //禁用 IW 的样式设置

WebApplication.RegisterCallBack('IWCallBack1', DoCallBack1); //注册回调; js 将通过指定名称("IWCallBack1")调用这里的 DoCallBack1 方法

gPath := TIWAppInfo.GetAppPath + 'Data.txt'; //用于测试文件的路径

if not FileExists(gPath) then //初始化测试文件

begin

with TStringList.Create do begin

Add(DateTimeToStr(Now));

SaveToFile(gPath, TEncoding.UTF8);

Free;

end;

end;

IWLabel1.RawText := True; //指定以 Html 的方式呈现其内容; 具有 RawText 属性的几个控件中, 发现 IWLabel1 最灵活.

IWLabel1.StyleRenderOptions.RenderSize := False; //既然前面已经指定了 IWTemplateProcessorHTML1.RenderStyles := False; 下面这些就应该不需要了, 但在 IE 下不行

IWLabel1.StyleRenderOptions.RenderPosition := False;

IWLabel1.StyleRenderOptions.RenderFont := False;

IWLabel1.StyleRenderOptions.RenderZIndex := False;

IWLabel1.StyleRenderOptions.RenderVisibility := False;

IWLabel1.StyleRenderOptions.RenderStatus := False;

IWLabel1.StyleRenderOptions.RenderAbsolute := False;

IWLabel1.StyleRenderOptions.RenderPadding := False;

IWLabel1.StyleRenderOptions.RenderBorder := False;

end;

procedure TIWForm1.DoCallBack1(EventParams: TStringList);

var

List: TStringList;

x: Integer;

begin

x := EventParams.Values['x'].ToInteger; //获取 js 传来的参数

List := TStringList.Create;

List.LoadFromFile(gPath, TEncoding.UTF8);

case x of

1: List.Add(DateTimeToStr(Now)); //参数是 1 表示添加

2: if List.Count > 0 then List.Delete(0); //参数是 2 表示删除

end;

IWLabel1.Text := List.Text.Replace(sLineBreak, '
'); //呈现;

List.SaveToFile(gPath, TEncoding.UTF8);

List.Free;

end;

initialization

TIWForm1.SetAsMainForm;

end.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值