The main purpose of what I'm trying to achieve is a hierarchy for my engine. I want to make a flexible class that will let me create children within it, so I don't need to create them in my main app. For example:
[pascal]
// ** I DO NOT WANT IT WORK LIKE THIS **
var
X: TClass1;
Y: TClass2;
begin
X := TClass1.Create('objectx');
Y := TClass2.Create('objecty', 3.14);
try
X.Add(Y);
finally
X.Free(); // Y is freed here
end;
end;
// ** INSTEAD, I WANT IT LOOK LIKE THIS **
var
X: TClass1;
begin
X := TClass1.Create('objectx');
try
with TClass2(X.AddNew(TClass2)) do
// do something
finally
X.Free();
end;
end;
[/pascal]
I could easily achieve this using metaclasses, but the problem is that I wanna pass an extra parameter to the TClass2 constructor.
Assuming for above posts, it is not possible, am I right?
Bookmarks