Hi at all
Hi at all,
this is an example, I'd like to implement a list of my generic class. Is it possible?
I've googled a lot whithout success... :(
Can someone help me?
Thanks.
TPlcType = class
private
FValue: T;
procedure SetValue(const Value: T); overload;
procedure SetValue(const AValue: Boolean); overload;
procedure SetValue(const AValue: Byte); overload;
procedure SetValue(const AValue: Word); overload;
public
property Value: T read FValue write SetValue;
end;
TPlc = class
private
FMyBool: TPlcType;
FMyByte: TPlcType;
FMyWord: TPlcType;
FMyList: TOBjectList<...> // ????
end;
this is an example, I'd like to implement a list of my generic class. Is it possible?
I've googled a lot whithout success... :(
Can someone help me?
Thanks.
TPlcType
private
FValue: T;
procedure SetValue(const Value: T); overload;
procedure SetValue(const AValue: Boolean); overload;
procedure SetValue(const AValue: Byte); overload;
procedure SetValue(const AValue: Word); overload;
public
property Value: T read FValue write SetValue;
end;
TPlc = class
private
FMyBool: TPlcType
FMyByte: TPlcType
FMyWord: TPlcType
FMyList: TOBjectList<...> // ????
end;
Not possible without a common base class for TPlcType.
ReplyDeleteDavid Millington you are right.... I didn't explain well.
ReplyDeleteStefan Glienke you are right too because you understood what I thought.
I want to replace my generics TPlcType <> with an object list to iterate all elements, but how Stefan Glienke said, I can not do that without a common base class.
I drowned in an inch of water.
Thanks.
Quick example how I would model it:
ReplyDeletetype
TPlcType = class
protected
function GetValueNonGeneric: TValue; virtual; abstract;
procedure SetValueNonGeneric(const Value: TValue); virtual; abstract;
public
property Value: TValue read GetValueNonGeneric write SetValueNonGeneric;
end;
TPlcType = class(TPlcType)
private
FValue: T;
procedure SetValue(const Value: T);
protected
function GetValueNonGeneric: TValue; override;
procedure SetValueNonGeneric(const Value: TValue); override;
public
property Value: T read FValue write SetValue;
end;
TPlc = class
private
FMyBool: TPlcType;
FMyByte: TPlcType;
FMyWord: TPlcType;
FMyList: TObjectList;
end;
{ TPlcType }
function TPlcType.GetValueNonGeneric: TValue;
begin
Result := TValue.From(FValue);
end;
procedure TPlcType.SetValue(const Value: T);
begin
FValue := Value
end;
procedure TPlcType.SetValueNonGeneric(const Value: TValue);
begin
FValue := Value.AsType;
end;