Lazarus

Using the Lazarus IDE => General => Topic started by: oopman on May 11, 2022, 09:02:35 pm

Title: Adding a new event corrupts use of Regions
Post by: oopman on May 11, 2022, 09:02:35 pm
If you use {$region} and {$endregion] to encapsulate your code. Then if you add a new event, Lazarus inserts the new code before the {$endregion} which screws up the folding.

{$region TForm1. SomeFunction}
procedure TForm1.SomeFunction}
begin
end ;
<<- If you add a new event it gets stuck in here instead of after the endregion statement?
{$endregion}
Title: Re: Adding a new event corrupts use of Regions
Post by: howardpc on May 11, 2022, 11:46:50 pm
CodeTools has several shortcomings. You have found one of them.
I'm sure a patch to improve this behaviour would be accepted.
Title: Re: Adding a new event corrupts use of Regions
Post by: Martin_fr on May 11, 2022, 11:49:28 pm
Tricky....

How can the IDE know if your "$region" is meant for just one method, or maybe all methods of a class? Or even some subset of the methods that you choose by some criteria? (I sometimes group 3 or 4 methods together).

Sorry, I am not aware of any setting to change this.

You could move the ";" from the "end;" to after the "endregion",
Code: Pascal  [Select][+][-]
  1. end
  2. {$endregion} ;
  3.  


Btw, I guess (not tested) that IFDEF may have similar issues.

-----------------
I don't know if the following has any chance at ever being done, or accepted as desirable feature.

There would need to be some setting, if a comment/directive should be attributed to the procedure body in front of it.

Maybe $endregion and $endif should be.... (and I guess that has a chance to be accepted)

Maybe spacing (empty lines) could be checked (e.g. for comments)... but not sure that is the best idea.
Title: Re: Adding a new event corrupts use of Regions
Post by: PascalDragon on May 12, 2022, 09:11:57 am
How can the IDE know if your "$region" is meant for just one method, or maybe all methods of a class? Or even some subset of the methods that you choose by some criteria? (I sometimes group 3 or 4 methods together).

Maybe use a rather simple approach: don't add them automatically into a region (if the user wants them there they can move it). If it already is in a region then keep it there when updating something.
Title: Re: Adding a new event corrupts use of Regions
Post by: oopman on May 26, 2022, 03:09:25 pm
Maybe I've missed it but I think the IDE adds a new event where it decides to and not where the cursor is? But I maybe wrong on this.

When you double-click on say an OnExit event to create an event, the IDE decides where to add the event code into the source file. I always have to cut the new event and paste it outside the $region.
TinyPortal © 2005-2018