Let's say that I have this kind of code in my unit:
TClass = class(tobject)
// ... implementation ...
end;
TControl = class(tobject)
private
FCheck: TClass
public
constructor Create(value: TClass);
// ... implementation...
end;
constructor TControl.Create(value: TClass);
begin
FCheck := value;
end;
As you can see the control class is going to take a TClass as parameter in the constructor, so I need to do something like this:
//The 'a' is a TClass that has already been created
c := TControl.Create(a);
try
//... do what I need ...
finally
c.Free;
end;
This is very basic: I am going to use a as parameter of the constructor but I cannot understand if what I am doing is safe. Do I have a memory leak?
In the constructor I do FCheck := value and I guess that it's correct because I am passing a reference to the object. Do I have to implement a destructor in TControl to free the FCheck? I cannot understand if I am managing correctly the FCheck object.