Sign in Join

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

Mailing lists / fpc-pascal / 2010-02

Assigning events in objects

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Zitt Zitterkopf

All,
I'm writing a TurboVision App to cross compile to Linux - but debugging on my main Win32 box.

In this app; I'm attempting to use the TFPTimer component to trigger an event every 1000ms. I can't get the bugger to compile; despite google searches and a lot of experience in Delphi.

The compiler always seems to throw an error simular to:

TVBOOT.PAS(52,20) Error: Incompatible types: got "<procedure variable type of   procedure(TObject) of object;Register>" expected "CLASSES.<procedure variable type of procedure(TObject) of object;Register>"

I began by using the advice of Graeme in the post: http://readlist.com/lists/lists.freepascal.org/fpc-pascal/0/3897.html

I know this is simple compiler gymnastics; but I just can't seem to figure it out. John

uses
CRT,App,Objects,Menus,Drivers,Views,Dialogs,
fpTimer;

type
 TBootApp = object(TApplication)
 private
  aTimer : TfpTimer;
 protected
  constructor Init;
  destructor Done; virtual;
  procedure InitStatusLine; virtual;
  procedure HandleEvent(var Event: TEvent); virtual;
  procedure Idle; virtual;
  function NewDialog : word;
 public
  procedure TimerTimer( Sender : TObject );
 end;
 PDemoDialog = ^TDemoDialog;
 TDemoDialog = object(TDialog)
 end;
var
 BootApp : TBootApp;
 Dialog  : PDemoDialog;
 DoDialog : Boolean;
constructor TBootApp.Init;
BEGIN
 aTimer := TFPTimer.Create(nil);
 aTimer.Interval := 500; //ms
 aTimer.Enabled := False;
 aTimer.OnTimer := @TimerTimer;   //compiler barfs <<<---- here!
END;
destructor TBootApp.Done;
BEGIN
 ATimer.Free;
END;
procedure TBootApp.TimerTimer( Sender : TObject );
BEGIN
END;
Michael Van Canneyt
to Zitt Zitterkopf
Zitt Zitterkopf wrote 5 lines
All, I'm writing a TurboVision App to cross compile to Linux - but debugging on my main Win32 box.   In this app; I'm attempting to use the TFPTimer component to trigger an event every 1000ms. I can't get the bugger to compile; despite google searches and a lot of experience in Delphi.

You are mixing a Delphi Class (TFPTimer) and a TV object (Tapplication). You can never mix them. You can use them independent of each other in the same application, but not assign a tp-style method to a delphi-style event handler.

You need to use a Delphi class TApplication object. If that is not possible, what you can do is create a go-between class:

TMyEvent = Class(TObject)
   Procedure MyEventHandler( Sender : TObject );
   MyApplication : TApplication
end;
Procedure TMyEvent.MyEventHandler(Sender : TObject );
begin
  MyApplication.TimerTimer(Sender);
end;

And assign this to the timer event:

  constructor TBootApp.Init;
  BEGIN
   FmyHandler:=TMyEvent.create;
   FMyhandler.MyApplication:=Self;
   aTimer := TFPTimer.Create(nil);
   aTimer.Interval := 500; //ms
   aTimer.Enabled := False;
   aTimer.OnTimer := @FMyHandler.MyEventHandler;
  END;

Michael.

Show quoted text 57 lines
  The compiler always seems to throw an error simular to:   TVBOOT.PAS(52,20) Error: Incompatible types: got "<procedure variable type of   procedure(TObject) of object;Register>" expected "CLASSES.<procedure variable type of procedure(TObject) of object;Register>" I began by using the advice of Graeme in the post: http://readlist.com/lists/lists.freepascal.org/fpc-pascal/0/3897.html   I know this is simple compiler gymnastics; but I just can't seem to figure it out.  John   uses CRT,App,Objects,Menus,Drivers,Views,Dialogs, fpTimer;   type  TBootApp = object(TApplication)  private   aTimer : TfpTimer;  protected   constructor Init;   destructor Done; virtual;   procedure InitStatusLine; virtual;   procedure HandleEvent(var Event: TEvent); virtual;   procedure Idle; virtual;   function NewDialog : word;  public   procedure TimerTimer( Sender : TObject );  end;  PDemoDialog = ^TDemoDialog;  TDemoDialog = object(TDialog)  end;   var  BootApp : TBootApp;  Dialog  : PDemoDialog;  DoDialog : Boolean; constructor TBootApp.Init; BEGIN  aTimer := TFPTimer.Create(nil);  aTimer.Interval := 500; //ms  aTimer.Enabled := False;  aTimer.OnTimer := @TimerTimer;   //compiler barfs <<<---- here! END; destructor TBootApp.Done; BEGIN  ATimer.Free; END;   procedure TBootApp.TimerTimer( Sender : TObject ); BEGIN END;
Marco van de Voort
to Zitt Zitterkopf: I'm writing a TurboVision App to cross compile to Linux - but debugging on my main Win32…

In our previous episode, Zitt Zitterkopf said:

Show quoted text 5 lines
I'm writing a TurboVision App to cross compile to Linux - but debugging on my main Win32 box. In this app; I'm attempting to use the TFPTimer component to trigger an event every 1000ms. I can't get the bugger to compile; despite google searches and a lot of experience in Delphi.

My guess is that you try to assign a methodvar of the TP object type to a variable from the Delphi class type.

Since a methodvar contains a reference to the object, there is a typemismatch for that.