Recent

Author Topic: Weird compiler behavior with event's definition/affectation  (Read 2083 times)

scalino

  • Newbie
  • Posts: 3
Weird compiler behavior with event's definition/affectation
« on: January 31, 2015, 12:12:36 pm »
Hi everyone,

got a weird behavior of the compiler related to Event affectation and inheritance and/or linking of units.

Got some unit with a class in which I have some typical event definition :

Type
  TSccMsgLogEvent = procedure (Agent, Msg, Str: String) of object;
 
  TSccMessage = class(TSccObject)
  private
  ...
    vOnNotify: TSccMsgLogEvent;
  public
  ...
    Property OnNotify: TSccMsgLogEvent read vOnNotify write vOnNotify;
end;

and some list class which is intended to load several TSccMessage, in which I got an implementation procedure for the event :

  (in list class)   Procedure MessageLog (Agent, Msg, Str: String);

then, when I affect the event property (in list class's loading procedure) :

  Msg.OnNotify:= @MessageLog;
 
 Everything works as expected. BUT!
 
 If I move the OnNotify event definition into the mother class of TSccMessage (so in TSccObject class [with FOnNotify in protected section], which is defined in another unit, so I also move the event type definition into that unit), then the compiler refuses to compile that same above line, saying :
 
 expected procedure (ShortString,ShortString,ShortString) of object; ... got procedure (AnsiString,AnsiString,AnsiString) of object
 
 Is it related to some kind of unit linking property which would transform Strings into ShortStrings...? a limitation of the compiler...? something else...?

Any thought accepted :)
 

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Weird compiler behavior with event's definition/affectation
« Reply #1 on: January 31, 2015, 01:40:35 pm »
I guess there is missing directive
Code: [Select]
{$H+}in the unit with is the class where is the event defined.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

scalino

  • Newbie
  • Posts: 3
Re: Weird compiler behavior with event's definition/affectation
« Reply #2 on: January 31, 2015, 03:55:10 pm »
oh! yeah most probably... thanks :)

 

TinyPortal © 2005-2018