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.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal