[fpc-pascal] Procedural generics question
Michael Van Canneyt
michael at freepascal.org
Fri Sep 4 09:51:14 CEST 2020
On Thu, 3 Sep 2020, Lars via fpc-pascal wrote:
> On 2020-08-26 05:44, Nico Neumann via fpc-pascal wrote:
>> The TypeInfo function checks the code during run-time thus the
>> generated code is 'bloated'. Better use the compiler intrinsic
>> GetTypeKind.
>>
>> {$mode objfpc}
>>
>> uses
>> typinfo;
>>
>> generic procedure Add<T>;
>> begin
>> if GetTypeKind(T) = tkInteger then WriteLn('an integer');
>> if GetTypeKind(T) = tkString then WriteLn('a string');
>> end;
>>
>
> That's great but if the type is something like a TRec (custom record) or
> a class, it won't be possible to check the types AFAICT because those
> are special built in type kind values for common basic types?
You will then get tkRecord or tkClass or tkObject. Of course this does not
tell you which record/class/object.
Michael.
More information about the fpc-pascal
mailing list