Hi Folks,
let's suppose i have a class like this.
TMyClass = Class
Private
FString:String;
FInteger:Integer;
Protected
//Some Fields, Functions, Procedures
Public
Constructor Create;
Destructor Destroy;Override;
And i want to add one more Field of
unknown ClassTpe
How would i go about it?
From Visual Basic i just had to implement an Interface, and i could assign it
Something like:
(I'm trying to speak Visual Basic in Pascal-Syntax!)
TInterFaceClass=Class
TRealClass1=class (Implements TInterFaceClass) //-->This is not Inheritance!!!
TRealClass2=class (Implements TInterFaceClass)
//some more classes, which are completely different from each other except they implement that Interface
//In VB i could do something like this
TSomeClass=Class
Private
FClass:TInterFaceClass;
Public
Property AClass:TInterFaceClass Read FClass Write FClass;
//Later in code:
SC:TSomeClass;
RC1:TRealClass1;
RC2:TRealClass2;
//Create the class etc.
SC.AClass:=RC1;
//DoSomething
SC.AClass:=RC2;
Possible?
I found this, which looks close as it gets to what i look for:
type
TGenericClass<T> = class
Field: T;
AString:String;
AInteger:Integer;
procedure Method(A: T);
Procedure DoSomething(AValue:Boolean);
Function GetSomething:String;
function Foo: T;
property Bar: T read Foo write Method;
end;
function TGenericClass<T>.Foo: T;
begin
Result := Field;
end;
procedure TGenericClass<T>.Method(A: T);
begin
Field:=A;
end;