Recent

Author Topic: No error when an event handler has wrong parameters  (Read 4254 times)

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
No error when an event handler has wrong parameters
« on: October 28, 2016, 01:01:44 pm »
Ran into this Problem while "converting" a Delphi Project into Lazarus/fpc.

The Event for OnDragOver or OnStartDrag (for a TListView in this case) in Delphi had one Parameter less, "Source".
Lazarus did NOT throw a warning or error on compiling, it results in an error in runtime...

We need a way to know about These Problems. Delphi at least asks for user Input.

Tried Delphi and Objfpc build modes.
Lazarus 1.6
fpc 3.0.0
« Last Edit: October 28, 2016, 01:09:15 pm by Girlbrush »
Getting back into programming after 8+ years.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: No error when an event handler has wrong parameters
« Reply #1 on: October 28, 2016, 01:23:39 pm »
If I look at the embarcadero website I can not find that. They are about identical between Laz and Delphi. Maybe someone set some default parameters?
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: No error when an event handler has wrong parameters
« Reply #2 on: October 28, 2016, 01:28:22 pm »
Yes, odd. I can't say what happened.

However, even in a brand new Project, if I let Lazarus make the Event handler Skeleton, I can just delete the whole Parameter list, and there is no warning about it.
For porting the Project over, it would be nice to get that Information. Before the Software has issues months down the line.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListView1DragOver();
  2. begin
  3.   //
  4. end;  
Getting back into programming after 8+ years.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4467
  • I like bugs.
Re: No error when an event handler has wrong parameters
« Reply #3 on: October 28, 2016, 02:51:34 pm »
However, even in a brand new Project, if I let Lazarus make the Event handler Skeleton, I can just delete the whole Parameter list, and there is no warning about it.
Yes it is true for event handlers stored in form files (.lfm). The streaming code is not able to check method signatures. There is no easy solution in sight unfortunately.
When assigning a handler in code, the compiler checks a method signature and gives an error if parameters don't match.
Streaming having no checks is a problem. It effectively prevents changing any event signature in any situation because it would silently create bugs in existing code.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: No error when an event handler has wrong parameters
« Reply #4 on: October 28, 2016, 04:48:09 pm »
I think we might try running VCL Units through the Lazarus importer, and see if that throws up anything.

Thanks for your answers so far, have a nice Weekend!
Getting back into programming after 8+ years.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: No error when an event handler has wrong parameters
« Reply #5 on: October 28, 2016, 06:42:06 pm »
Already reported as issue #23032.

Bart

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1314
    • Lebeau Software
Re: No error when an event handler has wrong parameters
« Reply #6 on: October 28, 2016, 10:34:09 pm »
The streaming code is not able to check method signatures.

That is true.  But that doesn't mean the IDE itself can't validate the signatures of design-time event handlers while saving the LFM.  The Delphi IDE does (see attached image).

There is no easy solution in sight unfortunately.

Sure there is, if the IDE has access to the RTTI at design-time.

Streaming having no checks is a problem. It effectively prevents changing any event signature in any situation because it would silently create bugs in existing code.

That same situation exists in Delphi, too.  But at least the IDE tries to help avoid it.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: No error when an event handler has wrong parameters
« Reply #7 on: October 31, 2016, 09:10:23 am »
Already reported as issue #23032.

Bart

It would be a nice-to-have for sure :)

I'm not sure what happened to the Code we tried to run through Lazarus that time, that it was actually missing a Parameter, that throws a warning in Delphi.
It did Highlight a possible issue if we go with importing some Code, and we assumed the IDE/Compiler would catch stuff like that.  ::)
Getting back into programming after 8+ years.

 

TinyPortal © 2005-2018