I have created an application that inside its' own create method just does this.
// Create the interface form that handles all the physical I/O
CommConnection := TCommForm.FormCreate(
CANUSB_COM, // For now hard coded to USB CAN dongle.
'CANopen', // Form Caption
'\Software\AutomationArtisans\CANopenCom', // Where to store config.
Sender);
CommConnection.OnRxMsg := SerialRxData;
After that the method
SerialRxData(Sender : TObject; var s : string);
is called to parse the string sent by the CANUSB dongle. When I switch over to an MCP2515 on a Pi or the internal CAN device on a Beagle I'll format the messages from those to look like what the CANUSB sends so the application won't know the difference. Just depends on what is passed to the FormCreate method.
Well guess what? In Lazarus this line kept failing with a missing parameters message.
CommConnection.OnRxMsg := SerialRxData;
I even created a simple two form "hello world" program to bring it down to basics. Still no luck. Eventually I had to comment out:
// {$mode objfpc}{$H+}
Replacing it with:
{$MODE Delphi}
After that it worked. And it still works on the Beagle running Linux.
Inside the main form I have:
// Connection to the CAN hardware
CommConnection : TCommForm;
// Called by the DoRxMsg method in TCommForm.
procedure SerialRxData(Sender : TObject; var s : string);
And the attached commform.pas shows the associated types and properties that make it all happen.
My question is:
If I went back to
{$mode objfpc}{$H+}
What needs to be done to be able to pass that callback function using the objfpc mode? Or is that even possible in non-Delphi mode?