Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-12

RTTI is always enabled??

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

This is a odd one (at least for me and another developer in tiOPF project). Why is RTTI information ALWAYS available?

See the example project below. It always returns that RTTI information is available when clearly it should not.

Kylix 3 help says that ClassInfo property should return nil if no RTTI is available. Tested with FPC 2.4.0-rc1, the test project below always prints that RTTI is available - which is wrong.

-------------------------------------------
program TestProject;
{$MODE objfpc}{$H+}
var
   TestObject: TObject;
function tiHasRTTI(AClass: TClass): Boolean;
var
   lClassInfo: Pointer;
begin
   lClassInfo := AClass.ClassInfo;
   Result := lClassInfo  nil;
end;
function tiHasRTTI(AObject: TObject): Boolean;
var
   lClass: TClass;
begin
   lClass := AObject.ClassType;
   Result := tiHasRTTI(lClass);
end;
begin
   TestObject := TObject.Create;
   if tiHasRTTI(TObject) then
     WriteLn('Class with RTTI.')          // always true???
   else
     WriteLn('Class without RTTI');
   if tiHasRTTI(TestObject) then
     WriteLn('Object with RTTI.')         // always true???
   else
     WriteLn('Object without RTTI');
   WriteLn;
   WriteLn('Press enter to exit.');
   ReadLn;
   TestObject.Free;
end.
--------------------------------------------

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Paul Ishenin
to Graeme Geldenhuys
Graeme Geldenhuys wrote 9 lines
This is a odd one (at least for me and another developer in tiOPF project). Why is RTTI information ALWAYS available? See the example project below. It always returns that RTTI information is available when clearly it should not. Kylix 3 help says that ClassInfo property should return nil if no RTTI is available. Tested with FPC 2.4.0-rc1, the test project below always prints that RTTI is available - which is wrong.

It is not the bug. This is a new feature required for showing of UnitName. Previosly this info was also available using TypeInfo() routine only compiler wrote nil pointer for the ClassInfo. Now it writes correct pointer.

This is delphi 2010 compatible behavior. Only info about published methods is not written for classes with {$M-}.

Best regards,
Paul Ishenin.

Reply by email

Graeme Geldenhuys
to Paul Ishenin
Paul Ishenin wrote
This is delphi 2010 compatible behavior. Only info about published methods is not written for classes with {$M-}.

So what is the correct way of asking if a class as RTTI (published properties) available? Because currently we have stacks of unit tests that fail in tiOPF due to this change - give always true when asking if publish properties (RTTI) is available.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Daniël Mantione
to Graeme Geldenhuys

Op Thu, 10 Dec 2009, schreef Graeme Geldenhuys:

Show quoted text 9 lines
Paul Ishenin wrote: > > This is delphi 2010 compatible behavior. Only info about published > methods is not written for classes with {$M-}. So what is the correct way of asking if a class as RTTI (published properties) available? Because currently we have stacks of unit tests that fail in tiOPF due to this change - give always true when asking if publish properties (RTTI) is available.

Published properties are far from the only information stored in RTTI, and therefore not the only reason why RTTI is generated. Automated types like widestring need for example RTTI to function.

I'd say check if the RTTI contains the data you need.

Daniël

Reply by email

Paul Ishenin
to Graeme Geldenhuys: So what is the correct way of asking if a class as RTTI (published properties) available?…
Graeme Geldenhuys wrote
So what is the correct way of asking if a class as RTTI (published properties) available? Because currently we have stacks of unit tests that fail in tiOPF due to this change - give always true when asking if publish properties (RTTI) is available.

If you want to get info about published properties then use the PropCount field of the class TTypeData record. If class has no RTTI it has PropCount = 0 I suppose. Although classes with RTTI but without published properties also have PropCount = 0 :)

Anyway, to give you a better answer I need more info about the goals of this info requesting.

Best regards,
Paul Ishenin.

Reply by email