[fpc-devel] RTTI is always enabled??

2009-12-10 Thread 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/

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] RTTI is always enabled??

2009-12-10 Thread Paul Ishenin

10.12.2009 17:01, Graeme Geldenhuys wrote:


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.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] RTTI is always enabled??

2009-12-10 Thread Graeme Geldenhuys
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/

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] RTTI is always enabled??

2009-12-10 Thread Daniël Mantione



Op Thu, 10 Dec 2009, schreef Graeme Geldenhuys:


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___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] RTTI is always enabled??

2009-12-10 Thread Paul Ishenin

10.12.2009 17:25, 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.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel