Recent

Author Topic: "procedure of object" problems...  (Read 12742 times)

Lerry

  • Newbie
  • Posts: 2
"procedure of object" problems...
« on: February 23, 2006, 04:52:55 pm »
Hi! I am new to FreePascal/Lazarus (being experienced Delphi programmer, however). Need your help. Maybe this is not the right place for this question, but… I found pretty interesting (and annoying) thing that I cannot explain. Maybe you can help. Take a look at the code:

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  ...;

type

  { TForm1 }

  TForm1 = class(TForm)
    ...
  private
    procedure AMethod();
  public
  end;

...

implementation

{ TForm1 }

type
  TMethod = procedure of object;

procedure TForm1.Button1Click(Sender: TObject);
var
  m: TMethod;
begin
  m:= AMethod;  // Get compile time error here!
end;

procedure TForm1.AMethod();
begin

end;

...

end.


I’ve declared TMethod type (procedure of object), and created a method AMethod() that takes no parameters. When I declare a variable of type TMethod and try to assign to that variable my AMethod(), compiler says: “Incompatible types: got “untyped” expected “<procedure variable type of procedure of object; Register>””. Who knows what this is???

Thanks.

JanH

  • Guest
RE: "procedure of object" problems...
« Reply #1 on: February 23, 2006, 05:16:40 pm »
declare your proc-Type like this:

type
  TMethod = procedure () of object;

JanH

  • Guest
RE: "procedure of object" problems...
« Reply #2 on: February 23, 2006, 05:17:39 pm »
edit:

and set m like this:

m := @AMethod;

Lerry

  • Newbie
  • Posts: 2
RE: "procedure of object" problems...
« Reply #3 on: February 23, 2006, 06:21:50 pm »
Oh! Thanks! So the answer is so simple! I was surprised when got that error. FPC behaves in a different way than Delphi compiler does...

RudieD

  • Full Member
  • ***
  • Posts: 234
RE: "procedure of object" problems...
« Reply #4 on: February 23, 2006, 08:40:39 pm »
If you don't want to use the @ you can always put {$MODE DELPHI} just after the unit name;
The FRED Trainer. (Training FRED with Lazarus/FPC)

kegge13

  • New Member
  • *
  • Posts: 45
    • the BistroMath project
Re: RE: "procedure of object" problems...
« Reply #5 on: April 04, 2019, 04:57:33 pm »
If you don't want to use the @ you can always put {$MODE DELPHI} just after the unit name;
Thanks for this excellent tip.

 

TinyPortal © 2005-2018