[fpc-pascal] How do I take the float type of a field from a record?

silvioprog silvioprog at gmail.com
Fri Dec 14 07:35:07 CET 2018


Hi.

Please consider the following code:

uses TypInfo;

type
  TTestRecord = record
    Member1: LongInt;
    Member2: Double;
    Member3: string;
    Member4: Extended;
  end;

var
  F: PManagedField;
  R: TTestRecord;
  T, T2: PTypeData;
  I: Integer;
begin
  R := Default(TTestRecord);
  T := GetTypeData(TypeInfo(R));
  F := PManagedField(PByte(@T^.TotalFieldCount) + 4);
  T2 := GetTypeData(F^.TypeRef);
  for I := 0 to Pred(T^.TotalFieldCount) do
  begin
    if F^.TypeRef^.Kind = tkFloat then
      WriteLn(F^.TypeRef^.Kind, ':', T2^.FloatType);
    Inc(F);
  end;
end.

it prints:

tkFloat:ftCurr
tkFloat:ftCurr

is there any chance to print it as below using FloatType?:

tkFloat:ftDouble
tkFloat:ftExtended

I solved it temporally using the following workaround (removing the last
four chars when the floating type is "Currency"):

WriteLn(F^.TypeRef^.Kind, ':tk', F^.TypeRef^.Name);

but I really would like to get the ordinal item instead of its name,
avoiding string handling.

Thank you!

--
Silvio Cl├ęcio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20181214/3dbd77e3/attachment.html>


More information about the fpc-pascal mailing list