I've a simple IntraWeb test project, My Unit1 has an IWform with 3 regions: header, body & footer as below:
type
TIWForm1 = class(TIWAppForm)
Body_Region: TIWRegion;
Header_Region: TIWRegion;
Footer_Region: TIWRegion;
public
end;
implementation
{$R *.dfm}
initialization
TIWForm1.SetAsMainForm;
end.
My Unit2 and Unit3 are an IWFrame and they have a button only as below:
type
TIWFrame2 = class(TFrame)
IWFrameRegion: TIWRegion;
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
end.
(unit3 same as unit2)
Now, I can assign a frame to the body region easily at design time by dropping Frames form the tool plate to that region.
The problem is how can I change it at runtime to unit3 Frame?
If I try to add it to type section like this
type
TIWForm1 = class(TIWAppForm)
Body_Region: TIWRegion;
Header_Region: TIWRegion;
Footer_Region: TIWRegion;
MyFram2: TIWFrame2; // added here
procedure IWAppFormShow(Sender: TObject);
public
end;
the system tries to remove it!
if I force to keep it to use it as
Body_Region.Parent := MyFram2;
I got nothing in the body region!
if I add it manually at design time I got the same declaration, I got it working but I cannot change it!
am I missing something here or it is impossible to do so?
btw I'm on Delphi Berlin 10.1 and IW14.1.12.
The "removal" of the declared field is not an IntraWeb thing, but a Delphi "feature". Declare it like this, inside a "private" section otherwise it will be treated as published:
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;
Remove OnShow event and use OnCreate event instead. Create your frame instances inside the OnCreate event, like this:
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;
Then you can make one visible and the other invisible setting Frame.IWFrameRegion visibility as shown above.