Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Is there a way to embed/instantiate a form frm one unit into a form in another unit at run time?
Thu, Mar 25 2021 8:18 PMPermanent Link

Gyro Cosmic

In particular I'm trying to:
-- build a main form with a TPagePanel at development time in the IDE as normal.
-- build additional forms with their own separate controls, logic, etc. in other units
-- at run time, create the additional forms and embed and them in TPages in the main form.

The goal being to develop each page in its own form so I can work on it and test it separate from the main form. If I put everything in the main form the amount of code and controls get huge and difficult to work with.

I've used this technique in Delphi quite a bit and am wondering if there's a way to do this in EWB?
Thu, Mar 25 2021 11:49 PMPermanent Link

Raul

Team Elevate Team Elevate

On 3/25/2021 8:18 PM, Gyro Cosmic wrote:
> In particular I'm trying to:
> -- build a main form with a TPagePanel at development time in the IDE as normal.
> -- build additional forms with their own separate controls, logic, etc. in other units
> -- at run time, create the additional forms and embed and them in TPages in the main form.
>
> The goal being to develop each page in its own form so I can work on it and test it separate from the main form. If I put everything in the main form the amount of code and controls get huge and difficult to work with.
>
> I've used this technique in Delphi quite a bit and am wondering if there's a way to do this in EWB?

Should work pretty much same way

1. create your form(s) - based on TForm
- make sure they are not auto-created by EWB in project settings

2. Create your main form with TPagePanel and create as many tabs as you
want (this can be done dynamically but for now do manually)

3. add forms you wish to embed into uses clause of main form

4. add OnCreate handler for the main form

4. create all the forms, supplying appropriate tab as owner

If each form is only embedded only once you can use form variable EWB
creates but if you have sames forms embedded in multiple places create
local variables in main form to hold formc

for example if i have 2 forms (TFormA and TFormB) and Page1 and Page2 as
pages of the pagepanel then i could do something like this in OnCreate

procedure TFormPages.FormPagesCreate(Sender: TObject);
begin
  FormA := TFormA.Create(Page1);
  FormB := TFormB.Create(Page2);
end;

Raul
Fri, Mar 26 2021 6:47 AMPermanent Link

Matthew Jones

I agree - I use embedded forms a lot. If you get to doing lists of the same form, that will work, but once you get to lots of them, it all gets slow. At that point you should virtualise them, but that's another level.



--

Matthew Jones
Fri, Mar 26 2021 7:00 AMPermanent Link

Gyro Cosmic

Thanks Raul. That worked really well. It's even simpler than Delphi.
Image