[fpc-pascal]Problem with TReader and integer idents
Mattias Gaertner
nc-gaertnma at netcologne.de
Tue Aug 6 13:11:17 CEST 2002
Hi all,
I have an object stream for a component with a published property Color: TColor. The stream contains the statement:
Color = clRed
Since 'clRed' is an identifier, TReader lookups for an IdentToInt function via FindIdentToInt declared in classes.pp. FindIdentToInt needs a pointer to a TTypeInfo.
The problem is that the TypeInfo pointer differs from unit to unit.
A TypeInfo(longint) in classes.pp is not the same as a TypeInfo(longint) in the program.
This is incompatible to Delphi.
So, the program can't register a valid TypeInfo pointer.
I guess, it's not easy to fix this, so I suggest a workaround:
The function FindIdentToInt can be extended to not only check for TypeInfo pointers, but also for the values in the typeinfo:
function FindIdentToInt(AIntegerType: Pointer): TIdentToInt;
var
i: Integer;
begin
with IntConstList.LockList do
try
for i := 0 to Count - 1 do
with TIntConst(Items[I]) do begin
if (IntegerType = AIntegerType)
// start of workaround --------------------
or ((PTypeInfo(AIntegerType)^.Name = PTypeInfo(IntegerType)^.Name)
and (PTypeInfo(AIntegerType)^.Kind = PTypeInfo(IntegerType)^.Kind))
// end of workaround --------------------
then
exit(IdentToIntFn);
end;
Result := nil;
finally
IntConstList.UnlockList;
end;
end;
The same can be applied to the FindIntToIdent function.
Mattias Gaertner
More information about the fpc-pascal
mailing list