Wednesday, March 11, 2020
How to Implement OnCreate Event for Delphi TFrame Object
How to Implement OnCreate Event for Delphi TFrame Object TFrame is a container for components; it can be nested within forms or other frames. A frame, like a form, is a container for other components. Frames can be nested within forms or other frames, and they can be saved on the Component palette for easy reuse. Missing OnCreate Once you start using frames, youll note theres no OnCreate event you can use to initialize your frames. In short, the reason that a frame does not have a OnCreate event is there is no good time to fire the event. However, by overriding the Create method you can mimic the OnCreate event. After all, the OnCreate for Forms gets fired at the end of the Create constructor - so overriding Create for Frames is as having the OnCreate event. Heres the source code of a simple frame exposing a public property and overriding the Create constructor: unit WebNavigatorUnit;interface uses à à Windows, Messages, SysUtils, Variants, Classes, à à Graphics, Controls, Forms, Dialogs, StdCtrls; type à à TWebNavigatorFrame class(TFrame)à à à à urlEdit: TEdit;à à private à à à à fURL: string;à à à à procedure SetURL(const Value: string) ;à à public à à à à constructor Create(AOwner: TComponent) ; override;à à published à à à à property URL : string read fURL write SetURL;à à end;implementation{$R *.dfm} constructor TWebNavigatorFrame.Create(AOwner: TComponent) ;begin à à inherited Create(AOwner) ;à //OnCreate code à à URL : http://delphi.about.com; end;procedure TWebNavigatorFrame.SetURL(const Value: string) ;begin à à fURL : Value; à à urlEdit.Text : Value; end;end. The WebNavigatorFrame acts as a website launcher hosting an edit and a button control. Note: if you are new to frames, make sure you read the following two articles: visual component development using frames, replacing tabsheets with frames.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.