Jump to content
Fons N

Remove empty event handler

Recommended Posts

Delphi Pro 11.2

 

Sometimes, you accidently click on the wrong event, it's automatically created but also automatically deleted when building and/or saving the code. This is still the case. But if you put in some code, but afterwards you changed your mind and delete all code between begin and end, then in past versions is would also delete the (now) empty event. It no longer does this. Unfortunately. Can anyone conform this?

 

Share this post


Link to post

Just update to 11.2 and also for me works as aspected.

I experienced too this problem in some forms in the previous versions (very rare). When happen I cut/paste the event piece of source at the unit end, then save and the empty event disappear as aspected.

Edited by Davide Angeli

Share this post


Link to post

The good news... it seems to be an isolated incident, because I cannot reproduce it. 

1 hour ago, Uwe Raabe said:

If anyone experiences this, it would be helpful to capture the current state of the unit. Then we can inspect these units to detect similarities.

If it happens again, I will save the pas and dfm files and report it here. Depending on the outcome, will then file a QR.

 

Share this post


Link to post

Delphi 11.3 Patch 1

Can confirm the problem. Seems to happen if the the genereated methode is in a compiler directive. Can anyone confirm this?
Is there already an open QR for it?

Edited by Philipp Hess
Added Question

Share this post


Link to post

This highly depends on the actual code. Without one can hardly reproduce.

Share this post


Link to post
procedure TFormFooBar.FormClick(Sender: TObject);
begin

end;

{ this comment prevents FormClick from being automatically removed }

procedure TFormFooBar.FormCreate(Sender: TObject);
begin
  // Blah
end;

 

Share this post


Link to post
procedure TFormFoo.FormClose(Sender: TObject; var Action: TCloseAction);
begin

end;

procedure TFormFoo.FormCreate(Sender: TObject);
begin

end;
//

procedure TFormFoo.FormDblClick(Sender: TObject);
begin

end;
{}

I've testet a bit further. FormCreate and FormDblClick would stay and Form Close would be removed.

Share this post


Link to post

So it boils down to adding a comment after the event body prohibits the deletion. This sound like a valid bug report.

  • Like 1

Share this post


Link to post
On 9/12/2022 at 6:00 AM, Fons N said:

Unfortunately. Can anyone conform this?

Did you try delete the "event line in Form definition" like this:

Quote

Form1 :TForm1;

...

public

   procedure MyEventRebeld(....);  <---- detele this line, and try save again... the IDE will try "remove it" for Form DFM, then, you'll can delete the event-body in "implementation section"

 

Share this post


Link to post
6 hours ago, Uwe Raabe said:

So it boils down to adding a comment after the event body prohibits the deletion. This sound like a valid bug report.

It's always been this way.

 

It would actually annoy me if they spent time fixing this instead of some of the more important stuff. Defeatism, I know.

Share this post


Link to post

This feature causes me more troubles than good. From time to time I add methods manually (important) to a form, write down name and args, generate method body, then go to somewhere else, do something and automatically hit Ctrl-S. Ouch, all my crafted declaration is gone! If only that removal could be undone!

Share this post


Link to post
1 hour ago, Fr0sT.Brutal said:

From time to time I add methods manually (important) to a form, write down name and args, generate method body, then go to somewhere else, do something and automatically hit Ctrl-S. Ouch, all my crafted declaration is gone!

Usually this will only happen to published event handlers with empty var and code (except inherited) sections. A simple line comment in the code section prohibits it. Also, if the method is created manually it probably shouldn't reside in the published section, unless it is meant to be wired automatically on load. In that case it is questionable why it is created manually in the first place.

Share this post


Link to post
3 hours ago, Uwe Raabe said:

A simple line comment in the code section prohibits it.

Of course I'm aware. But these comments must be added manually which I forget to do from time to time. As for the section, these methods are event handlers that couldn't be added via clicking for some reasons.

Anyway if any code changes were considered ordinary text edits and added to undo log, life would be much easier

Edited by Fr0sT.Brutal

Share this post


Link to post
13 minutes ago, Fr0sT.Brutal said:

But these comments must be added manually which I forget to do from time to time.

Perhaps I am too used to add methods with MMX Code Explorer, which inserts a TODO to each method by default.

Share this post


Link to post
6 hours ago, Fr0sT.Brutal said:

As for the section, these methods are event handlers that couldn't be added via clicking for some reasons.

Only empty, published methods are removed. Are you saying that you manually add published event handlers?

Share this post


Link to post

here I have:

type
  TForm1 = class(TForm)
    procedure Button1Click(Sender: TObject);
    ...
  PUBLISHED // without it and "empty" method = will be removed! else any other combination, not!
    procedure Hello(const a: string);
  private
  //
  public
  //
...

procedure TForm1.Hello(const a: string);
begin
  // with this, dont will be removed!
  // else, if "empty" and "dont using "PUBLISHED" above = it will be removed
end;

 

Edited by programmerdelphi2k

Share this post


Link to post
On 4/21/2023 at 10:32 PM, Anders Melander said:

Only empty, published methods are removed. Are you saying that you manually add published event handlers?

Yep, I rarely care about this. Handlers go to handlers.

On 4/21/2023 at 3:46 PM, Uwe Raabe said:

Perhaps I am too used to add methods with MMX Code Explorer, which inserts a TODO to each method by default.

Nice feature!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×