Is there a way to do that? :
other than of courseCode:with TLabel.create(nil) do begin ... someList.Add(this TLabel?); end;
Code:L:=tlabel.create with L do begin ... someList.Add(L) end
Is there a way to do that? :
other than of courseCode:with TLabel.create(nil) do begin ... someList.Add(this TLabel?); end;
Code:L:=tlabel.create with L do begin ... someList.Add(L) end
No that's not possible. Best you can do is:
(You shouldn't create them with nil. Otherwise you have to do the garbage collection (freeing them) all by yourself.)Code:someList.Add(TLabel.create(form1)); with TLabel(someList.Items[someList.Items.Count-1]) do begin ... end;
I actually don't do that but it was shorter to type this way
thanks
If you are adding all of this labels to some list you could go and create your own TMyLabel class which is deprecated class of TLabel. Doing so you can change default TLabel constructor so that Label gets added into your list ass soon as it is created:
And now you can simply use:Code:type TMyLabel = class(TLabel) public constructor Create(Owner: TComponent; List: TObjectList); end; .... constructor TMyLabel.Create(Owner: TComponent; List: TList); begin inherited Create(Owner); List.Add(self); end;
Code:with TMyLabel.create(Form1,someList) do begin ... end;
Bookmarks