Recent

Author Topic: Adding a new event corrupts use of Regions  (Read 469 times)

oopman

  • New Member
  • *
  • Posts: 11
Adding a new event corrupts use of Regions
« 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}

howardpc

  • Hero Member
  • *****
  • Posts: 3983
Re: Adding a new event corrupts use of Regions
« Reply #1 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.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7939
  • Debugger - SynEdit - and more
    • wiki
Re: Adding a new event corrupts use of Regions
« Reply #2 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.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4116
  • Compiler Developer
Re: Adding a new event corrupts use of Regions
« Reply #3 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.

oopman

  • New Member
  • *
  • Posts: 11
Re: Adding a new event corrupts use of Regions
« Reply #4 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