Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable code formatting for a section in Delphi [duplicate]

Yesterday I discovered the Format Source feature in Delphi, and it saves me a lot of time.

However, I've discovered that it corrupts the layout of anonymous procedures. Is there a setting that can improve this result?

For example, if I have the following code:

procedure TServerThread.cbUpdateStreamProgBar(Precentage: Integer);
begin
  Synchronize(
    procedure
    begin
      FrmMain.StreamProgressBar.StepBy(Precentage);
    end);
end;

After I auto-format the source code, it is collapsed as follows:

procedure TServerThread.cbUpdateStreamProgBar(Precentage: Integer);
begin
  Synchronize( procedure begin FrmMain.StreamProgressBar.StepBy
    (Precentage); end);
end;

How can I avoid this?


1 Answers

You have to upgrade to a newer version of Delphi as noted in comments. The automatic source formatter in XE2 is ok for anonymous methods.

As an alternative you can try the Experimental GExperts IDE PlugIn. If it does not format correctly, there is source code to add your own style.

See also Delphi code formatter.


Update, coming to think about it, there is a workaround. A bit tedious though. By selecting parts of your source, only the selection will be formatted by pressing ctrl+D.

like image 69
LU RD Avatar answered Dec 15 '25 21:12

LU RD