Somehow I could never convince myself to using frames in Delphi (TFrame).
My biggest issue was all those missing events that TForm has, such as OnCreate and OnShow.
So, for some time now, I'm using standard forms that behave like frames,
but descend from TForm (thus, they inherit all standard events of TForm).
The implementation of such forms is really simple -
just override the CreateParams method:
type
TPaneForm = class(TForm)
protected
procedure CreateParams(var AParams: TCreateParams); override;
end;
...
procedure TPaneForm.CreateParams(var AParams: TCreateParams);
begin
inherited CreateParams(AParams);
AParams.Style := AParams.Style or WS_CHILD;
end;
TCreateParams holds the information necessary for creating a window in Windows.
Things like caption, position and dimensions, style.
Although CreateParams is not documented, its meaning here should be obvious.
Finally, WS_CHILD creates a child window without a menu bar.
To use these forms as frames on other forms, override the CreateParams procedure in your form
and then create it as any other Delphi control that is then embedded in another form:
LPane := TPaneForm.Create(AOwner);
LPane.Parent := AOwner;
LPane.Visible := TRUE; // not necessary if Visible is set to TRUE in TPaneForm
And, of course, you have all TForm's properties and events,
as well as full handling of Visual Form Inheritance.
Another plus side to this solution is that any form that you might have
can be hosted by another form. For instance, let's say that we have several forms
that configure something (a program, a component, etc.). On the one hand,
sometimes you might want to show a single form only (such as formatting of an axis of a chart)
or host all forms in another form (such as different tabs in a preferences dialog window).
Top
|