1

Topic: LogObject troubles

Hi there,

I'm having trouble logging objects that I build myself. The SmartInspect console keeps telling me 'LogObject: AInstance argument has no RTTI'. I do have published properties in the objects in question (As I understand it RTTI information is only available for published properties), but to no avail.

Any thoughts?

Gerben ten Wolde,

Ten Hove ICT

2

Re: LogObject troubles

Hello,

Additionally to making the properties published you have to inherit from the TPersistent class to get RTTI data associated with a class in Delphi. Just adding TPersistent as the base class should do the trick. Hope that helps!

Dennis Gurock,
Director & Co-Founder
Gurock Software

3

Re: LogObject troubles

Thanks, that solved it.

4

Re: LogObject troubles

Another way to add the RTTI information is by using the $M compiler directive.

Taken from the Delphi 7 help file:

A class cannot have published members unless it is compiled in the {$M+} state or descends from a class compiled in the {$M+} state. Most classes with published members derive from TPersistent, which is compiled in the {$M+} state, so it is seldom necessary to use the $M directive.

Example:

unit uSomeObject;

interface

uses
  Classes;

{M+}

type
  TSomeObject = class(TObject)
  private
    FCaption;
    { Private Declarations }
  protected
    procedure SetCaption(AValue: string);
    function GetCaption: string;
    { ProtectedDeclarations }
  public
    { Public Declarations }
  published
    property Caption: string read GetCaption write SetCaption;
    { Published Declarations }
  end;

For more information see the topic "Published members" in the Delphi 7 help file.

5

Re: LogObject troubles

Well, bummer. The forum doesn't allow leading spaces. Also my example has a mistake. {M+} should have been {$M+}