
March 26th, 2013, 11:45 AM
|
|
Contributing User
|
|
Join Date: Sep 2008
Posts: 44
Time spent in forums: 10 h 7 m 32 sec
Reputation Power: 5
|
|
When using CREATE( OWNER ) parameter, the OWNER will be who will delete the new component. When using NIL, will be you who delete. When using SELF, usually, will be "the FORM", or, another container (FORM, FRAME, DATAMODULE, PANEL, etc...)
--------------------------------------
var
xCmpTmp:TButton;
begin
try
try
xCmpTmp := TButton.create;
xCmpTmp.propertyXXXX := valueXXXXX;
except
... exception control here
end;
finally
{ if Assigned(xCmpTmp) then FreeAndNil(xCmpTmp); // if dont need more }
end;
if Needs of the component in another place in your software, MAKE IT not in a handler event, procedures, functions etc... MAKE IT in a place BEFORE use it and DELETE it in another place
example:
1 - make it before called the forms that using it
2 - erase (free) it after all use this components.
You can use a ARRAY for stored your components:
var
xCmpTmpArray:Array[0..10] of TButton;
....
xCmpTmpArray[0] := TButton.Create;
For use one "OPEN ARRAY" ( xCmpTmpArray:Array of TButton) you need one code more complex to control "what" will deleted.
Making components in RunTime
http://delphi.about.com/od/kbcurt/a/dynamiccreation.htm
Last edited by emailx45 : March 26th, 2013 at 11:49 AM.
|