How can I stop autogenerating code blocks? lazarus / 9-Editor ---------------------------------------------------------------------- dpap · 2025-02-15 06:35 When I add a control's event the IDE auto-duplicates some other event blocks (empty of code). How can I prevent this? ---------------------------------------------------------------------- LV · 2025-02-15 08:03 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 · 2025-02-15 08:18 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 ---------------------------------------------------------------------- Martin_fr · 2025-02-15 09:12 Quote from: dpap on February 15, 2025, 07:35:10 amWhen 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 · 2025-02-15 09:41 It would be helpful if the OP provided a simple, reproducible example; otherwise, we're just guessing while solving a puzzle. ---------------------------------------------------------------------- dpap · 2025-02-15 09:55 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 · 2025-02-15 10:03 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 ---------------------------------------------------------------------- dpap · 2025-02-15 11:23 Yes! it is VERY ANNOING ---------------------------------------------------------------------- Martin_fr · 2025-02-15 11:31 Quote from: dpap on February 15, 2025, 10:55:03 amTo 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 · 2025-02-15 12:14 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 · 2025-02-15 12:29 Quote from: LV on February 15, 2025, 01:14:42 pmThe 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   TForm1=class     procedure Button1Click(Sender: TObject);   ...   end; implementation procedure TForm1.Button1Click(Sender: TObject);begin  // dpap's codeend;   procedure TForm1.Button1Click(Sender: TObject);begin end; 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 · 2025-02-15 12:49 @Martin_fr. OK, inverse problems often have multiple solutions. It would be interesting to know the reason for this case. ---------------------------------------------------------------------- dpap · 2025-02-15 16:44 @Martin_fr. Yes this is the case. Where can you find "auto remove empty procedures" option in Laz3.6? ---------------------------------------------------------------------- Martin_fr · 2025-02-15 17:03 Quote from: dpap 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? 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 · 2025-02-15 17:31 Something related to ? https://forum.lazarus.freepascal.org/index.php/topic,55819.msg415098.h tml#msg415098 ---------------------------------------------------------------------- Martin_fr · 2025-02-15 17:55 Quote from: Paolo on February 15, 2025, 06:31:08 pmSomething related to ? https://forum.lazarus.freepascal.org/index.php/topic,55819.msg415098.h tml#msg415098 Reading the top post of that link => sounds like the same issue. I thought it had been mentioned before. ---------------------------------------------------------------------- LV · 2025-02-15 18:05 Thanks,@Paolo. The example provided at https://forum.lazarus.freepasca l.org/index.php/topic,55819.msg415098.html#msg415098 illustrates the clear reason: the code in the implementation section was manually written. Replacing this with a Ctrl+Shift+C procedure resolves the issue. ---------------------------------------------------------------------- dpap · 2025-02-15 21:29 SOLVED The problem was the different definition of the method in the implementation section. The code was ported from Delphi and at the method's definition a variable was declared as Char but in the implementation section was declared as ANSIchar (as it was in Delphi). I can't recall if I was me who changed the declarations or the code transporter. Anyway thanks for your help