Sign in Join

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

Mailing lists / lazarus / 2018-10

Can't assign event procedure....

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Bo Berglund

This is what I have:

In a unit where a logging class is defined:

type
  TRxEvent = procedure (const Buffer: TBytes) of object;
...
  TWiFiCommLogger = class(TThread)
  private
  ...
    FOnRxData: TRxEvent;
  ...
  public
  ...
    property OnRxData: TRxEvent read FOnRxData write FOnRxData;
  ...
end;
procedure TWiFiCommLogger.Execute;
begin
  while not Terminated do
  begin
     ...
      if Assigned(FOnRxData) then
      begin
        FOnRxData(FBuffer);
        SetLength(FBuffer, 0);
      end;
     ...

Then in the form unit where I want to use this:
...

  private

...

    procedure OnRxSS(Buf: TBytes);

...
end;

In the form constructor:

procedure TfrmCommTest.FormCreate(Sender: TObject);
...
  FLogSS := TWiFiCommLogger.Create;
  FLogSS.OnRxData := OnRxSS;  // <== Error on this line
...

When I compile this I get the following error:

formcommtest.pas(112,22) Error: Incompatible types: got "TfrmCommTest.OnRxSS(TBytes);" expected "<procedure variable type of procedure(const TBytes) of object;Register>"

What am I doing wrong here?

I have written similar types of programs where I have used this kind of construction and it has worked fine (in Delphi).

Both the form file and the unit where the handler class is defined have been set to:

{$mode Delphi}
Bo Berglund Developer in Sweden

Reply by email

gabor
to Bo Berglund

Missing "const" before Buf?

procedure OnRxSS(*const* Buf: TBytes);

W dniu 2018-10-13 o 20:43, Bo Berglund via Lazarus pisze:

Show quoted text 7 lines
Then in the form unit where I want to use this: ... private ... procedure OnRxSS(Buf: TBytes); ... end;

Regards, Michał.

Reply by email

Vojtěch Čihák

Did you try simply to add "const"?
 
V.
______________________________________________________________

Show quoted text 5 lines
Od: "Bo Berglund via Lazarus" Komu: Datum: 13.10.2018 20:43 Předmět: [Lazarus] Can't assign event procedure....

What am I doing wrong here?

I have written similar types of programs where I have used this kind of construction and it has worked fine (in Delphi).

Both the form file and the unit where the handler class is defined have been set to:

 {$mode Delphi}
Bo Berglund Developer in Sweden --

Reply by email

Bo Berglund
to Bo Berglund: This is what I have: In a unit where a logging class is defined: type TRxEvent =…
Bo Berglund wrote
type TRxEvent = procedure (const Buffer: TBytes) of object;

Of course posting here is the best way to actually discover the solution just a few minutes afterwards...

The const specifier was missing in the implementation on the form where I wanted to use the class object. Adding it in let the compile succeed!

Sorry for the noise.

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Bo Berglund
Bo Berglund wrote
Sorry for the noise.

This is just a test of posting via GMane since my posts on the fpc list have been rejected. Reason unknown to me. Worked for years until now...

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Bo Berglund
Bo Berglund wrote 8 lines
On Sat, 13 Oct 2018 21:00:51 +0200, Bo Berglund via Lazarus wrote: >Sorry for the noise. > This is just a test of posting via GMane since my posts on the fpc list have been rejected. Reason unknown to me. Worked for years until now...

After rebooting my router, thus obtaining a different Internet IP address my rejection from the fpc.general list disappeared. Surely a GMane thing...

Bo Berglund Developer in Sweden

Reply by email