[Lazarus] Can't assign event procedure....

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Can't assign event procedure....

Free Pascal - Lazarus mailing list
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

--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Can't assign event procedure....

Free Pascal - Lazarus mailing list
Missing "const" before Buf?

procedure OnRxSS(*const* Buf: TBytes);

W dniu 2018-10-13 o 20:43, Bo Berglund via Lazarus pisze:
> Then in the form unit where I want to use this:
> ...
>    private
> ...
>      procedure OnRxSS(Buf: TBytes);
> ...
> end;

Regards, Michał.
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Can't assign event procedure....

vojtech.cihak
In reply to this post by Free Pascal - Lazarus mailing list

Did you try simply to add "const"?

 

V.

______________________________________________________________
> Od: "Bo Berglund via Lazarus" <[hidden email]>
> Komu: [hidden email]
> 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

--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Can't assign event procedure....

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Sat, 13 Oct 2018 20:43:43 +0200, Bo Berglund via Lazarus
<[hidden email]> 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

--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Can't assign event procedure....

Free Pascal - Lazarus mailing list
On Sat, 13 Oct 2018 21:00:51 +0200, Bo Berglund via Lazarus
<[hidden email]> 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

--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Can't assign event procedure....

Free Pascal - Lazarus mailing list
On Sun, 14 Oct 2018 17:51:09 +0200, Bo Berglund via Lazarus
<[hidden email]> wrote:

>On Sat, 13 Oct 2018 21:00:51 +0200, Bo Berglund via Lazarus
><[hidden email]> 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

--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus