[fpc-devel] {$M+} and forward declarations do not work
    Graeme Geldenhuys 
    graemeg at opensoft.homeip.net
       
    Tue Dec 20 08:59:17 CET 2005
    
    
  
Peter Vreman wrote:
> Please submit always complete code. Now we need to guess what is wrong and
> in a lot of cases we can't reproduce it with our own code like in this
> situation. The code below works perfectly:
Sorry about that.  Strangely enough, your example runs fine here as 
well.  Below is my complete code that fails. Moving the $M around the 
actual class declaration makes it work.
I am using FPC 2.0.1 that came with Lazarus 0.9.10 on Windows 2000.
------------------------------------------------
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
   Classes, SysUtils, LResources, Forms,
   Controls, Graphics, Dialogs, Buttons,
   StdCtrls;
type
{$M+}
   TMyTestObject = class;
{$M-}
   TForm1 = class(TForm)
      Button2: TButton;
      Memo1: TMemo;
      procedure Button2Click(Sender: TObject);
   private
   public
   end;
   TMyTestObject = class(TObject)
   private
      FIntProp: integer;
      FStringProp: string;
   public
   published
     property StringProp: string read FStringProp write FStringProp;
     property IntProp: integer read FIntProp write FIntProp;
   end;
var
   Form1: TForm1;
implementation
uses
   TypInfo;
procedure TForm1.Button2Click(Sender: TObject);
var
   O: TMyTestObject;
   i: Longint;
   lPropFilter: TTypeKinds;
   lCount: Longint;
   lSize: Integer;
   lList: PPropList;
begin
   O := TMyTestObject.Create;
   lPropFilter := [tkInteger, tkAString];
   lCount  := GetPropList(O.ClassInfo, lPropFilter, nil, false);
   lSize   := lCount * SizeOf(Pointer);
   GetMem(lList, lSize);
   memo1.Lines.Add('Total property Count: ' + IntToStr(lCount));
   lCount := GetPropList(O.ClassInfo, lPropFilter, lList, false);
   for i := 0 to lCount-1 do
   begin
     memo1.Lines.Add('Property '+IntToStr(i+1)+': ' + lList^[i]^.Name);
   end;
   FreeMem(lList);
   O.Free;
   memo1.Lines.Add('---------------');
end;
initialization
   {$I unit1.lrs}
end.
------------------------------------------------
Regards,
   - Graeme -
    
    
More information about the fpc-devel
mailing list