Discussion:
[Lazarus] Can't assign event procedure....
Bo Berglund via Lazarus
2018-10-13 18:43:43 UTC
Permalink
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

--
gabor via Lazarus
2018-10-13 18:57:54 UTC
Permalink
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ł.
--
Vojtěch Čihák via Lazarus
2018-10-13 18:58:07 UTC
Permalink
Did you try simply to add "const"?
 
V.
______________________________________________________________
> Od: "Bo Berglund via Lazarus" <***@lists.lazarus-ide.org>
> Komu: ***@lists.lazarus.freepascal.org
> 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
***@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus <https://lists.lazarus-ide.org/listinfo/lazarus>
Bo Berglund via Lazarus
2018-10-13 19:00:51 UTC
Permalink
On Sat, 13 Oct 2018 20:43:43 +0200, Bo Berglund via Lazarus
<***@lists.lazarus-ide.org> 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

--
Bo Berglund via Lazarus
2018-10-14 15:51:09 UTC
Permalink
On Sat, 13 Oct 2018 21:00:51 +0200, Bo Berglund via Lazarus
<***@lists.lazarus-ide.org> 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

--
Bo Berglund via Lazarus
2018-10-14 16:17:59 UTC
Permalink
On Sun, 14 Oct 2018 17:51:09 +0200, Bo Berglund via Lazarus
<***@lists.lazarus-ide.org> wrote:

>On Sat, 13 Oct 2018 21:00:51 +0200, Bo Berglund via Lazarus
><***@lists.lazarus-ide.org> 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

--
Loading...