Link to home
Start Free TrialLog in
Avatar of hellfire052497
hellfire052497

asked on

Frames question

Hi,

Is it possible to load different frames in a single container, I need to create a wizard, I think using different Forms (frames) will be easier. But When I select the frame container, it asks me what frame to use, and I see no option to load another frame. or unload one.
Or should I create the container at runtime, when needed?? if so how?

Any hints tips or advice, on making wizards is appreciated, Since they will be graphic heavy, I need to keep the memory load low. And I know using panels just eats up memory. because they are all created at runtime. While the forms are not. Is this also the case for Frames?

Thanks
Marc
Avatar of Epsylon
Epsylon

You can dynamically create frames you build in the designer. Below the source of the main unit (unit1). It uses unit2 which has a few components on it.
Button1 creates an instance of the frame (defined in unit2) and shows it on the main form.
Button2 removes it.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    Frame: TFrame;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Frame := TFrame2.Create(Self);
  Frame.SetBounds(150, 100, 200, 200);
  Frame.Parent := Self;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Frame.Free;
end;

end.
Please take a look at my plugin-interface demo too:

http://www5.ewebcity.com/epsylon/download.asp?file=PluginInterface.zip


Regards,

Epsylon.
To unload a frame simply delete it.
Two put two frames on one form simply select one put in on the form and select the next one. If you want two frames acting as one, make a third frame that consists of the two previous frames and drop this single third frame on your form. The demo in delphi directory  \\demos\frames\db\...
is also a good example of frame capibilities and mixing frames and databases.

Cheers
Gerhardus
If your frame is dropped on the form in design time it is created when you start you application because it is then only a fancy container. Epsylon's demo will work fine to create a frame dynamically just make sure that the frames unit is included in the forms uses clause that want to create it.

Weereens Groete
Gerhardus
Using table control with be more easy.
But using table control may need more memory.
If you apreciate with it,I can provide some code for you.
Avatar of hellfire052497

ASKER

Hi all,

Thanks for the info, Epsylon's first solution is exactly what I had in mind. So Epsylon if you want to lock the question, so I can give you the points.

Thanks
Marc
ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Epsylon,

I have one question left. I cannot find an Oncreate event with frames. I normally use this to initialize stuff.

Any idea how to do this with a Frame??

Thanks
Marc
Hi Marc, in the frame-unit you can override the constructor and add aditional code like this:


unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TFrame2 = class(TFrame)
    Edit1: TEdit;
  private
    { Private declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
  end;

implementation

{$R *.DFM}

{ TFrame2 }

constructor TFrame2.Create(AOwner: TComponent);
begin
  inherited;
  // out your own stuff here
end;

end.
Hi Epsylon,

Thanks for the info. It just reminded me why I love Delphi so much ;-)

Take Care
Marc