Is there any way to get RTTI hints for a real48 and shortstring variable in a structure where FieldType is nil in TRttiField?

StackOverflow https://stackoverflow.com/questions/16340089

  •  14-04-2022
  •  | 
  •  

Question

I have discovered what I think is an odd oversight (probably intentional) on the part of the Extended RTTI feature in Delphi.

I would like to dump all the fields in an record type that has about 1500 different fields in it. Yes, seriously.

Some of them are of type real48 and some are shortstring, for those two, it appears that FieldType is nil for these types at runtime:

function TRttiField.GetValue(Instance: Pointer): TValue; 
var
  ft: TRttiType;
begin
  ft := FieldType;
  if ft = nil then
    raise InsufficientRtti; // This fires!
  TValue.Make(PByte(Instance) + Offset, ft.Handle, Result);
end;

If I was willing to assume that all nil-fieldtype fields are in fact real48's, I could simply use the offset and (if the field width is 6) grab a real48 value.

However the second complication is that all shortstring (ie string[30]) types are similarly afflicted.

Has anybody got these two Ancient Pascal Types to work with modern Extended RTTI? Right now I'm using a best-guess approach, and where that fails I am hardcoding rules by name of the field, but if there was some technique I could use that would get me there without having to write a lot of code to extract information from all these old pascal file-of-records that I am modernizing, I would appreciate a better idea.

Was it helpful?

Solution

Unfortunately Real48 does not have any type info.

You can see that when you try compile this:

program Project1;

begin
  TypeInfo(Real48);
end.

The same goes for the string[n] syntax. But there you could probably fix it by defining your own string types like:

type
  string30 = string[30];

That alone would not include the rtti for the record field so you need to hack/fix the rtti as I showed here: https://stackoverflow.com/a/12687747/587106

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top