新建 StandAlone Application 工程后, 再通过 File > New > Other.. > IntraWeb > New Form 添加两个窗体.

然后 TIWForm1 上放两个 TIWButton, 在 TIWForm2 和 TIWForm3 上各放一个 TIWButton. 测试代码用到三个窗体的 OnCreate 和每个按钮的 OnClick 事件.

Unit1 中的代码:
uses ServerController, Unit2, Unit3;

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  IWServerController.HistoryEnabled := True; //使浏览器后退、前进按钮有效
  IWButton1.Caption := 'IWForm2';
  IWButton2.Caption := 'IWForm3';
end;

procedure TIWForm1.IWButton1Click(Sender: TObject);
begin
  TIWForm2.Create(WebApplication).Show; //建立并显示 TIWForm2; 执行后 WebApplication.ActiveForm 就从 TIWForm1 变为 TIWForm2
end;

procedure TIWForm1.IWButton2Click(Sender: TObject);
begin
  TIWForm3.Create(WebApplication).Show; //
end;

initialization
  TIWForm1.SetAsMainForm; //这是 TIWAppForm 的 Class 方法; 其作用是建立并设置当前窗口为主窗口(其实在 IW 中只有 ActiveForm, 无所谓 MainForm )
                          //当然也同样设置其他窗体是首先被激活的窗体


Unit2 中的代码:
procedure TIWForm2.IWAppFormCreate(Sender: TObject);
begin
  IWButton1.Caption := Name; //只是用不同的标题区别一下
end;

procedure TIWForm2.IWButton1Click(Sender: TObject);
begin
  Release; //释放后, TIWForm1 就出来了, 达到了返回的目的
           //为什么 IW 提倡使用 Release 而不是通常的 Free 呢?
           //我经过测试发现, Release 和 Free 是有区别的; 官方资料中介绍: IWApp;ication 内部还维护着一个 FReleasedForms 列表.
end;


Unit3 中的代码:
procedure TIWForm3.IWAppFormCreate(Sender: TObject);
begin
  IWButton1.Caption := Name;
end;

procedure TIWForm3.IWButton1Click(Sender: TObject);
begin
  Release;
end;


还有一个问题, 在这里我们并没有引用 IWInit, 代码中的 WebApplication 是哪来的呢? 原来 TIWBaseForm(TIWAppForm < TIWForm < TIWBaseHTMLForm < TIWBaseForm)也提供了 WebApplication.
经测试, 两个 WebApplication 都指向了同一个 TIWApplication 对象, 挺方便的.

感觉 IW 比传统的 VCL 更巧妙些.

posted on 2014-06-03 17:07  万一  阅读(8924)  评论(6编辑  收藏  举报