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

I found that I consider it a strange oversight (possibly intentional) from the extended RTTI function in Delphi.

I would like to reset all fields in a record type that contains about 1,500 different fields. Yes seriously.

Some of them are of type real48, and some are shortstring, for these two it seems that the FieldType for these types at runtime is zero:

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 were ready to assume that all nil-fieldtype fields are actually real48, I could just use the offset and (if field width 6) capture the value of real48.

However, the second complication is that all types of short strings (ie string[30] ) also suffer.

Has anyone got these two types of ancient pascals to work with modern advanced RTTI? Right now I am using the best-guessed approach, and where this fails, I hard code the rules by the field name, but if there was some technique that I could use, it could get me there without having to To write a lot of code to extract information from all of these old archive files that I will upgrade, I would appreciate a better idea.

+4
source share
1 answer

Unfortunately, Real48 has no type information.

You can see that when you try to compile this:

 program Project1; begin TypeInfo(Real48); end. 

The same applies to the syntax of the string [n]. But there you can probably fix this by specifying your own string types, for example:

 type string30 = string[30]; 

Only this will not include rtti for the record field, so you need to hack / fix rtti, as I showed here: fooobar.com/questions/440659 / ...

+4
source

All Articles