【问题标题】:Changing Intraweb IWFrames at runtime在运行时更改 Intraweb IWFrame
【发布时间】:2017-09-03 13:44:15
【问题描述】:

我有一个简单的 IntraWeb 测试项目,我的 Unit1 有一个包含 3 个区域的 IWform:页眉、正文和页脚,如下所示:

type
  TIWForm1 = class(TIWAppForm)
    Body_Region: TIWRegion;
    Header_Region: TIWRegion;
    Footer_Region: TIWRegion;
  public
  end;

implementation

{$R *.dfm}


initialization
  TIWForm1.SetAsMainForm;

end.

我的 Unit2 和 Unit3 是一个 IWFrame,它们只有一个按钮,如下所示:

type
  TIWFrame2 = class(TFrame)
    IWFrameRegion: TIWRegion;
    Button1: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

{$R *.dfm}

end.

(unit3与unit2相同)

现在,我可以在设计时通过将框架从工具板拖放到该区域轻松地为主体区域分配框架。

问题是如何在运行时将其更改为 unit3 Frame?

如果我尝试将它添加到这样的类型部分

type
  TIWForm1 = class(TIWAppForm)
    Body_Region: TIWRegion;
    Header_Region: TIWRegion;
    Footer_Region: TIWRegion;

    MyFram2: TIWFrame2; // added here

    procedure IWAppFormShow(Sender: TObject);
  public
  end;

系统会尝试删除它!

如果我强制保留它以将其用作

Body_Region.Parent := MyFram2;

我的身体区域什么都没有!

如果我在设计时手动添加它,我得到了相同的声明,我得到它的工作,但我不能改变它!

我在这里遗漏了什么还是不可能做到这一点?

顺便说一句,我在 Delphi Berlin 10.1 和 IW14.1.12 上。

【问题讨论】:

    标签: delphi intraweb


    【解决方案1】:

    声明字段的“删除”不是 IntraWeb 的事情,而是 Delphi 的“功能”。像这样声明它,在“私人”部分内,否则它将被视为已发布:

    TIWForm1 = class(TIWAppForm)
      Body_Region: TIWRegion;
      Header_Region: TIWRegion;
      Footer_Region: TIWRegion;
      procedure IWAppFormCreate(Sender: TObject);  // use OnCreate event
    private
      FMyFram2: TIWFrame2; // put it inside a "Private" section. 
      FMyFram3: TIWFrame3;
    public
    end;
    

    移除 OnShow 事件并改用 OnCreate 事件。在 OnCreate 事件中创建框架实例,如下所示:

    procedure TIWForm1.IWAppFormCreate(Sender: TObject);
    begin
       FMyFram2 := TIWFrame2.Create(Self);  // create the frame
       FMyFram2.Parent := Body_Region;      // set parent
       FMyFram2.IWFrameRegion.Visible := True;  // set its internal region visibility.
    
       // the same with Frame3, but lets keep it invisible for now  
       FMyFram3 := TIWFrame3.Create(Self);
       FMyFram3.Parent := Body_Region;           
       FMyFram3.IWFrameRegion.Visible := False;
    
       Self.RenderInvisibleControls := True;  // tell the form to render invisible frames. They won't be visible in the browser until you make them visible
    end;
    

    然后你可以让一个可见而另一个不可见设置Frame.IWFrameRegion可见性如上所示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-04
      • 2011-04-10
      • 2011-01-01
      • 2010-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多