Recent

Author Topic: Removing empty methods  (Read 7378 times)

Rave

  • Full Member
  • ***
  • Posts: 160
Removing empty methods
« on: March 30, 2013, 07:52:15 am »
One thing I don't understand is why Lazarus doesn't remove empty methods upon compiling app. Delphi had it since... forever?

For those that may say that it is useful for stubs... Well, I've said *empty* methods. If you will need it later on because it's stub, it should be enough to put comment there in order to it not being removed.

So following method:
Code: [Select]
procedure Form1.OnClick(Sender:TObject);
begin

end;

would get removed upon compiling application, but following
Code: [Select]
procedure Form1.OnClick(Sender:TObject);
begin
//stub
end;

or even

Code: [Select]
procedure Form1.OnClick(Sender:TObject);
begin
//
end;
would not. This is particularly useful for those who missclicked event handler field (instead of double clicking, e.g. Form.OnClick, clicked Form.OnClose and thus made unnecessary method) or those who clicked proper handler, but later on found better solution which made it pointless (and empty).

If you still aren't convinced, it can be always made an option (opt-in or opt-out - I don't care).

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3633
  • I like bugs.
Re: Removing empty methods
« Reply #1 on: March 30, 2013, 08:10:04 am »
IDE Options -> Editor -> Completion and Hints -> Auto remove empty methods

Rave

  • Full Member
  • ***
  • Posts: 160
Re: Removing empty methods
« Reply #2 on: March 30, 2013, 08:14:14 am »
Oh, didn't know that, thanks!
Locking then.

Rave

  • Full Member
  • ***
  • Posts: 160
Re: Removing empty methods
« Reply #3 on: March 30, 2013, 10:46:54 pm »
It doesn't seem to work.

Accidentally added wrong event handler so now I have empty method:
Code: [Select]
procedure Tmain.Image1Click(Sender: TObject);
begin

end;

but IDE doesn't want to remove it, despite selecting option mentioned above.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8108
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Removing empty methods
« Reply #4 on: March 30, 2013, 11:07:32 pm »
Does it still have the interface in the class definition? i.e.:
Quote
Tmain = class(TForm)
...
procedure Image1Click(Sender: TObject);
...
end;

jeff_swi

  • Newbie
  • Posts: 3
Re: Removing empty methods
« Reply #5 on: March 31, 2013, 12:29:33 am »
I had this same problem today. After I selected the option to automatically remove empty methods, the methods remained. I even re-started the IDE with no change.

I was able to get it to work only after deleting the white space between the begin and end for the method(s). I then created empty methods again to make sure it would remove the methods automatically. The empty methods were removed after I clicked the Save button.
Windows 7 (64-bit); Lazarus 1.0.14 r43446 FPC 2.6.2 i386-win32-win32/win64

Rave

  • Full Member
  • ***
  • Posts: 160
Re: Removing empty methods
« Reply #6 on: March 31, 2013, 12:47:30 am »
Thanks, Jeff. Your solution worked (although restarting IDE wasn't necessary). I think this glitch should be fixed (or was it? I'm still on Laz 1.0 due to later version adding some performance issues with drawing on TCanvas which isn't wanted when developing games).

User137

  • Hero Member
  • *****
  • Posts: 1790
    • Nxpascal home
Re: Removing empty methods
« Reply #7 on: March 31, 2013, 01:01:34 am »
Test on Lazarus v1.1.
- Start empty project.
- Doubleclick on form, and onFormCreate event is created.
- Compile project, onFormCreate event is automatically removed.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5631
    • wiki
Re: Removing empty methods
« Reply #8 on: March 31, 2013, 03:21:03 am »
I had this same problem today. After I selected the option to automatically remove empty methods, the methods remained. I even re-started the IDE with no change.

I was able to get it to work only after deleting the white space between the begin and end for the method(s). I then created empty methods again to make sure it would remove the methods automatically. The empty methods were removed after I clicked the Save button.

Odd. I just tested on 1.1. White spaces are ignored. (I did switch of trim trailing spaces, so I could enter white spaces, that would be kept)


tintinux

  • Sr. Member
  • ****
  • Posts: 299
    • Gestinux
Re: Removing empty methods
« Reply #9 on: August 02, 2013, 01:42:30 pm »
IDE Options -> Editor -> Completion and Hints -> Auto remove empty methods

I think it should be checked by default, for a better Delphi compatibility.

Regards

Tintinux
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.