Recent

Author Topic: How can I stop autogenerating code blocks?  (Read 788 times)

dpap

  • Jr. Member
  • **
  • Posts: 52
How can I stop autogenerating code blocks?
« on: February 15, 2025, 07:35:10 am »
When I add a control's event the IDE auto-duplicates some other event blocks (empty of code).
How can I prevent this?

LV

  • Full Member
  • ***
  • Posts: 237
Re: How can I stop autogenerating code blocks?
« Reply #1 on: February 15, 2025, 09:03:25 am »
If you do not require Lazarus' assistance, you can manually write the code, including the event handlers. Good luck and have patience on this journey.   ;)
Simple example: dynamically generated button. https://wiki.freepascal.org/TButton.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8306
Re: How can I stop autogenerating code blocks?
« Reply #2 on: February 15, 2025, 09:18:17 am »
I see what you're getting at, and agree that it could be an irritant. /However/ the action of "adding a control's event" is fundamentally that of assigning a named handler, which is what the IDE is doing on your behalf.

Try selecting "none" in the dropdown, or selecting an existing name.

Apart from that the obvious questions: what version of Lazarus etc.?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10897
  • Debugger - SynEdit - and more
    • wiki
Re: How can I stop autogenerating code blocks?
« Reply #3 on: February 15, 2025, 10:12:13 am »
When I add a control's event the IDE auto-duplicates some other event blocks (empty of code).
How can I prevent this?

You mean, if you e.g., add on "OnClick" for "Button1", then it will also add maybe "FormOnPaint" => even thought that already exists. So you then have twice "TForm1.OnPaint", one with your code, and one empty?

That would be a bug. I have heard of it before, never had it myself. Not sure what causes it.

If I would guess, I would say, it may happen if
- your code has errors, and the IDE does not find the already existing code (because the IDE stops reading at the error)
- If the IDE for other reasons cannot read your code. (E.g. there are some issues with generic functions).
- maybe other reasons....

But unfortunately I don't know the real answer.

LV

  • Full Member
  • ***
  • Posts: 237
Re: How can I stop autogenerating code blocks?
« Reply #4 on: February 15, 2025, 10:41:38 am »
It would be helpful if the OP provided a simple, reproducible example; otherwise, we're just guessing while solving a puzzle.

dpap

  • Jr. Member
  • **
  • Posts: 52
Re: How can I stop autogenerating code blocks?
« Reply #5 on: February 15, 2025, 10:55:03 am »
To be more clear, I want to autogenerate the event's implementation block ONLY when I double click at the event's row at object inspector. Now, when I'm doing this, the IDE generates the block (as expected) but duplicates other event's block that already exist! This behavior makes me crazy because every time I must delete them. It seems that the IDE checks the existents of all the events implementation and some of them could not find, although they exist, and recreates them.
The program compiles and runs ok, so the code hasn't problems. Anyway, I want to prevent this auto generation except the one witch I really needed

cdbc

  • Hero Member
  • *****
  • Posts: 1933
    • http://www.cdbc.dk
Re: How can I stop autogenerating code blocks?
« Reply #6 on: February 15, 2025, 11:03:43 am »
Hi
That must indeed be annoying, (never experienced it my self) does it happen in other apps / projects too, if so, are there any common traits between them, that peeks the eye?!?
Just curious - Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

dpap

  • Jr. Member
  • **
  • Posts: 52
Re: How can I stop autogenerating code blocks?
« Reply #7 on: February 15, 2025, 12:23:20 pm »
Yes! it is VERY ANNOING >:(

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10897
  • Debugger - SynEdit - and more
    • wiki
Re: How can I stop autogenerating code blocks?
« Reply #8 on: February 15, 2025, 12:31:03 pm »
To be more clear, I want to autogenerate the event's implementation block ONLY when I double click at the event's row at object inspector. Now, when I'm doing this, the IDE generates the block (as expected) but duplicates other event's block that already exist! This behavior makes me crazy because every time I must delete them. It seems that the IDE checks the existents of all the events implementation and some of them could not find, although they exist, and recreates them.

Yes, the 2nd part of this is a bug. See my previous post. But I don't know more about it.

Also yes, the first part: If the IDE completes a method then it completes all of them. Of course it should only update the ones that are really missing.
There is a setting "Update all method signatures" in Tools > Options > Codetools >Class completion.
I don't know, if it will work. It is meant for when you complete a class in the editor using shift ctrl C. So I don't know if it affects completion via OI.
Also, by the name, it is meant about updates, which is, if a method exist, but a parameter was changed/renamed. Though I believe it includes creation too.

Even if that "solves" the issue, it may leave you with other misbehaviour. Because it would not fix the underlying problem, and that is likely to cause issues in other situations too.


Check if there is an open issue for it.

And see if you can provide a sample project on which it happens.

Also check, if it is related to any config you have.
Start your ide with a clean config
  lazarus.exe --pcp-c:\new_empty_folder
If that fixes it, then also supply your config if you create an issue. Otherwise no one will be able to ever reproduce it.

LV

  • Full Member
  • ***
  • Posts: 237
Re: How can I stop autogenerating code blocks?
« Reply #9 on: February 15, 2025, 01:14:42 pm »
I attempted to reproduce the problem without knowing the specifics of your project. I started by creating an empty project and adding two buttons. In the Object Inspector, I assigned OnClick events to both buttons.

Next, I decided to delete Button1 both from the form and the source code editor in the implementation section: procedure TForm1.Button1Click(Sender: TObject); (yellow rectangle).

Then in the object inspector, I assign OnEnter events to Button2.

The result is shown in the attached screenshot.

The issue arises because, when Button1 is deleted from the form, the corresponding procedure declaration in the interface section—`procedure Button1Click(Sender: TObject);`—remains in the type description, indicated with a red rectangle. Once I manually deleted this procedure, everything worked fine.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10897
  • Debugger - SynEdit - and more
    • wiki
Re: How can I stop autogenerating code blocks?
« Reply #10 on: February 15, 2025, 01:29:14 pm »
The issue arises because, when Button1 is deleted from the form, the corresponding procedure declaration in the interface section—`procedure Button1Click(Sender: TObject);`—remains in the type description, indicated with a red rectangle. Once I manually deleted this procedure, everything worked fine.

Not sure if that is the same issue.

You only have 1 (ONE) method "Button1Click"
And most important, there is only on >Body< for that method (only one occurrence in the implementation section).

Hovewer, if I understand dpap correct (and the sporadic few other reports of the past), then dpap gets TWO method bodies.

Code: Pascal  [Select][+][-]
  1.   TForm1=class
  2.      procedure Button1Click(Sender: TObject);
  3.    ...
  4.    end;
  5.  
  6. implementation
  7.  
  8. procedure TForm1.Button1Click(Sender: TObject);
  9. begin
  10.   // dpap's code
  11. end;  
  12.  
  13. procedure TForm1.Button1Click(Sender: TObject);
  14. begin
  15.  
  16. end;  
  17.  

The last block is an empty duplicate. And it breaks the code.



@LV: What you have, that the method is not deleted, when you delete the button => look at "auto remove empty procedures" => that should help.

Obviously if you have actual code inside, you need to clean it up yourself. The IDE shouldn't just delete your code.

LV

  • Full Member
  • ***
  • Posts: 237
Re: How can I stop autogenerating code blocks?
« Reply #11 on: February 15, 2025, 01:49:28 pm »
@Martin_fr. OK, inverse problems often have multiple solutions. It would be interesting to know the reason for this case. :)

dpap

  • Jr. Member
  • **
  • Posts: 52
Re: How can I stop autogenerating code blocks?
« Reply #12 on: February 15, 2025, 05:44:47 pm »
@Martin_fr. Yes this is the case. Where can you find "auto remove empty procedures" option in Laz3.6?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10897
  • Debugger - SynEdit - and more
    • wiki
Re: How can I stop autogenerating code blocks?
« Reply #13 on: February 15, 2025, 06:03:55 pm »
@Martin_fr. Yes this is the case. Where can you find "auto remove empty procedures" option in Laz3.6?
Tools > Options > Editor > Completion and hints

But that is unlikely to do anything. If it can't find them before creating them, it wont find them for removal.

There is the
 "Update all method signatures" in Tools > Options > Codetools >Class completion.
as mentioned before.

But to really get it fixed, there needs to be a bug report, and a way to reproduce it. All else will just replace one problem with another problem.

Paolo

  • Hero Member
  • *****
  • Posts: 569

 

TinyPortal © 2005-2018