type TParent=class public member1:Integer; end; TChild=class(TParent) public member2:Integer; end; TGArray<T: TParent>=class public function test:T; end; implementation var g:TGArray<TChild>; function TGArray<T>.test:T; begin Result:=??.create; // <<<< Problem ! end; begin g := TGArray<TChild>.Create; g.test.member2 := 1234; end.
g.test should return an instance of the class. I have tried several things:
1. Result := Result.create;
The purpose of this is to create a common array of classes. The array is stored inside the general class and returns instances, but how?
If I do this, I will cut my code 3 times, but I cannot do this. Please suggest any solution.
source share