I need to create procedure in delphi which will cast array of anonymous type to array of specified type. What I'am trying to accomplish:
procedure Foo (myArray: array of AnonymousType; typeName: string)
begin
//do smth on this array
end;
This is actually a procedure for a game where player can define his own script. This script is called at runtime so above structure is the only one which will actually work.
What I'am trying to do is pass 2 parameters into this function:
- array of user defined type (which I don't know in game)
- type of this array passed by string
And then procedure should convert passed array into this specific type. I read about TList, but I cannot declare static type.
In .NET I'am able to pass array of dynamic (or even object) and cast it to destination type using linq or simply iterate through dynamic list.
Is something like that actually possible in delphi? Any help will be appreciated.
Variant, for instance. Or instances of type-specific class wrappers derived fromTObject. What you are describing makes no sense in compiled languages like Delphi, only in scripted languages like Javascript/VBScript, Python, etc. In .NET,dynamicis just a placeholder for any object that derives fromSystem.Dynamic.DynamicObject- Remy Lebeauarray of const. - Victoria