[fpc-pascal] Pass type as function parameter

Marco van de Voort fpc at pascalprogramming.org
Wed Mar 24 11:10:14 CET 2021


Op 2021-03-24 om 11:05 schreef Michael Van Canneyt via fpc-pascal:
>
>> Would it be possible in FPC to pass a type of a variable as a 
>> parameter to
>> a function?
>>
>> e.g.
>>  MyFunction(integer);
>>
>> I have legacy C code that does this via a macro. Hopefully, it can be 
>> done
>> so I do not need to change the existing code too badly.
>
> This is not possible as such.
>
> What you can do is use generics
>
> MyFunction<integer>
>
> or use typeinfo:
>
> MyFunction(TypeInfo(Integer));
>
> Which of the 2 you need to use depends on the code of course.
>
Or variants. Or in an emergency: start using/creating an external 
preprocessor.



More information about the fpc-pascal mailing list