Reputation: 449
TMyPanel = class(TPanel)
public
procedure AfterConstruction; override;
end;
procedure TMyPanel.AfterConstruction;
begin
inherited AfterConstruction;
Caption := '';
end;
I want to clear the caption during construction, but this code does not work as I expect. It will not set the caption to empty string. If I assign ' ' (space) to Caption, it will remain, but this is not a proper solution.
I am using Delphi 2006.
Upvotes: 1
Views: 1558
Reputation: 5869
Try this:
uses
ExtCtrls, StrUtils;
type
TMyPanel = class(TPanel)
public
procedure Loaded; override;
end;
procedure TMyPanel.Loaded;
inherited;
Caption := EmptyStr;
end;
Tested and appears to work fine in XE2.
EDIT:
The reason this works where the method shown in the OP doesn't is because Loaded
is called after the object's property values have been assigned from the DFM file.
The overridden call to AfterConstruction
takes place after the initial creation of the object, but before the property values have been assigned from the Form's DFM, meaning that whatever property values you assign in your AfterConstruction
method will be immediately replaced by whatever value is specified for that same property in the DFM.
Loaded
takes place at the very end of the construction order, so whatever value you assign there will be final.
Upvotes: 5