This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I have an application that I think TFrames will be very helpfull with.
I have a form with an extendednotebook. A couple of the tabs will use exactly the same form, so I created that as a Frame.
I was hoping to do a couple things by doing this.
- Avoid implementing the tab multiple times
- The Main form unit was getting a LOT of code in it due to lots of different tabs, so I was hoping to separate the code into separate units for each tab.
A simplified version shown here. In reality there are a ton of fields and methods in the frame
in a common unit TMyObject is something like this (With many more fields and some methods/properties for updating them that are not necessary to show here)
type
TMyObject = class(TObject)
Field1: string;
Field2: string;\
``
end;
var
MyObject1: TMyObject;
MyObject2: TMyObject;
In the main Form Unit:
TForm1 = class(TObject)
Notebook: TExtendedNotebook;
Tab1: TTabSheet;
Tab2: TTabSheet;
Frame1_1: TFrame1; // Placed on Tab1 via the Form Designer
Frame1_2: TFrame1; // Placed on Tab2 via the Form Designer
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
Frame1_1 := Frame1_1.Init( myObject1 );
Frame1_2 := Frame1_2.Init( myObject2 )
end;
The Frame Unit:
TFrame1 = class(TFrame)
fMyObject: TMyObject;
procedure editField1( sender: TObject );
procedure editField2( sender: TObject );
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure Init( sender: TObject; myObject: TMyObject);
end
implementation
constructor TFrame1.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
end;
destructor TFrame1.Destroy;
begin
inherited Destroy;
end;
procedure TFrame1.Init( sender: TObject; myObject: TmyObject);
begin
fMyObject := MyObject;
EditField1.Text := MyObject.Field1;
EditField2.Text := MyObject.Field2;
end;
procedure TFrame1.editField1Exit( sender: TObject );
begin
fMyObject.Field1 := edit1.Text;
end;
procedure TFrame1.editField2Exit( sender: TObject );
begin
fMyObject.Field2 := edit2.Text;
end;
end;
When I switch to the each tab, the forms are displayed, fields are populated thanks to the init procedure.
I can tab thru the fields just fine and edit the data but none of the "OnExit" methods I created for this the controls on this frame are executed.
In fact none of the methods for the Frame object controls are executed, such as onClick or onChange events. And before you ask, Yes they are defined in the objects events via the Object Inspector at design time.
Obviously I'm not doing this right. Do I totally misunderstand how frames work?
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/pascal/comm...