[fpc-pascal] How to set a type as a variable?
Felipe Monteiro de Carvalho
felipemonteiro.carvalho at gmail.com
Tue Aug 24 07:41:22 CEST 2010
No, if all your types are classes descending from the same root you
can do it is like this:
type
TBaseType = class;
procedure somemethod();
end;
TExtendedType = class(TBaseType);
TBaseTypeClass = class of TBaseType;
procedure (value: TBaseType; type_: TBaseTypeClass)
begin
value := type_.Create();
value.somemethod();
end;
And you can call your procedure as:
proc(somevar, TExtendedType);
For other types you need to use generics.
--
Felipe Monteiro de Carvalho
More information about the fpc-pascal
mailing list