Is there a way to determine the type of variable passed as an argument to a method? Consider the class:
TSomeClass = class procedure AddToList<T: TDataType; U: TListClass<T>>(Element: T; List: U); end;
with method implementation
procedure TSomeClass.AddToList<T, U>(Element: T; List: U); begin if Element is TInt then List.AddElement(TInt.Create(XXX)) else if Element is TString then List.AddElement(TString.Create(YYY)); end;
where TInt.Create () and TString.Create () have different sets of arguments, but they both inherit from TDataType.
Now I know that the is operator cannot be used like that, but is there a legitimate alternative that does what I ask here?
generics delphi
conciliator
source share