gpt4 book ai didi

delphi - 在运行时更改 Intraweb IWFrame

转载 作者:行者123 更新时间:2023-12-01 23:20:56 26 4
gpt4 key购买 nike

我有一个简单的 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.

(单元3与单元2相同)

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

问题是如何在运行时将其更改为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;

我的 body 区域什么也没有!

如果我在设计时手动添加它,我会得到相同的声明,它可以工作,但我无法更改它!

我在这里遗漏了一些东西还是不可能这样做?

顺便说一句,我使用的是 Delphi Berlin 10.1 和 IW14.1.12。

最佳答案

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

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 可见性设置为一个可见,另一个不可见,如上所示。

关于delphi - 在运行时更改 Intraweb IWFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46024037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com