//在新建 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); //注册回调
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.
使用 IntraWeb (45) - 活用 IntraWeb
原文:http://www.cnblogs.com/del/p/3977660.html