6

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
    I'm not sure that's possible, there are many language features that the IDE's editor is not really "aware" of, but wait for others to answer this, I'm interested as well... don't forget to add the delphi version tag to this question. –  Mar 18 '13 at 01:19
  • 1
    @ComputerSaysNo Thank you for the support and i, myself really hope there's a solution to this. (i just hope not a 3rd party utility) –  Mar 18 '13 at 01:22
  • AFAIK this is a feature starting with XE3 – Sir Rufo Mar 18 '13 at 06:46
  • 2
    @SirRufo No, it's been around a lot longer than that. – David Heffernan Mar 18 '13 at 08:26
  • A formatter has to parse the entire file. There will be no option to get it to skip certain parts of the file. You are also two versions out of date. If it's a bug it won't be fixed in XE. Perhaps it's already fixed in XE3. A third party formatter or a Delphi upgrade is what you need. – David Heffernan Mar 18 '13 at 08:27
  • @DavidHeffernan XE3 Source Formatter does format anonymous procedures as expected (thats the feature I was talking about). But reading my own comment, it sounds also vague to me, what feature I was talking about ;o) – Sir Rufo Mar 18 '13 at 08:33
  • XE2 Source Formatter does format anonymous methods as expected as well. – iMan Biglari Mar 18 '13 at 08:49
  • I downgraded to XE on purpose because i do not need all the additional stuff (Profiling QA, FireMonkey, 64Bit) XE2+ comes with... jesus now i feel so bummered and makes me think of upgrading, omg !!! -_- –  Mar 18 '13 at 09:13
  • See [`Delphi 2010: anyone got the right settings for the formatter not to fold anonymous methods?`](http://stackoverflow.com/q/1957922/576719). – LU RD Mar 18 '13 at 11:47
  • @LURD Some users do not want to do a major version upgrade just to have a tiny simple bug fixed, but thank you for the concern. –  Mar 18 '13 at 11:59
  • @user1803300, yes it's frustrating when bugs are not fixed, even more that fixes are introduced in newer version and not backported. See my answer for alternatives. – LU RD Mar 18 '13 at 12:24
  • 1
    I find XE2 (with all updates included and using vcl in 32/64 bit) pretty solid. Unit scoped names is easy to handle and no show stopper. – LU RD Mar 18 '13 at 21:50

1 Answers1

2

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.

Community
  • 1
  • 1
LU RD
  • 34,438
  • 5
  • 88
  • 296
  • Yes, sadly this is a known bug in Delphi XE's code formatter that will not be fixed except by ditching XE and moving up to XE2 or XE3. – Warren P Mar 18 '13 at 21:20