zoukankan      html  css  js  c++  java
  • 使用 IntraWeb (3)


    新建 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 更巧妙些.

  • 相关阅读:
    dwSun带你选Python的编辑器/IDE
    ubuntu中文乱码解决
    解决matplotlib中文显示
    1506.01186-Cyclical Learning Rates for Training Neural Networks
    1503.02531-Distilling the Knowledge in a Neural Network.md
    1804.03235-Large scale distributed neural network training through online distillation.md
    mysql导入太慢解决方法
    已某个时间单位(日月周年)来分割时间段
    阿里云邮件推送
    阿里云短信推送服务
  • 原文地址:https://www.cnblogs.com/del/p/3765652.html
Copyright © 2011-2022 走看看