Jump to content
emileverh

Formatting inline var

Recommended Posts

Hi!

 

For D11; Can anybody tell me what setting(s) I needin Tools-Options-Language-Formatter ( or may be it's not possible at all ) the format an inline var. I want to have the keyword in front of the variable, now a line break is added. By the way the line break is not added in a 'regular' declaration

 

This is what I want:

 

TfrmMain.SomeStuff;

var x : integer;

begin

  ... lots of code

   var  settings := dtmSettings.ReadRecord;

end;

 

 

And Delphi 11 does this:

TfrmMain.SomeStuff;

var x : integer;

begin

  ... lots of code

   var 

   settings := dtmSettings.ReadRecord;

end;

 

Any help is welcome 😉

  • Like 1

Share this post


Link to post

The GExperts formatter seems to do what you ask, here.  I have never used the one that comes in the IDE, though.

Share this post


Link to post

That is not possible. Download the book by Bent Normann Olsen (docx). Page 71.

See above:classic_biggrin:

Edited by Stano

Share this post


Link to post
54 minutes ago, Stano said:

That is not possible. Download the book by Bent Normann Olsen (docx). Page 71.

 

It's hard to find that reference after you made 100 new editions without any official source.

Share this post


Link to post
Guest

YES! it's possible do it!

my way around this little obstacle:

  1. go to "Tools -> Language -> Formatter -> Profiles and Status" and save your profile to disk!
  2. open this file and search for:
    1. <Option Name="DelphiFormatter.NewLineForEachVarAndConstElement" Type="Borland.Together.OpenAPI3.Config.LF_CASE" Category="DelphiLinebreaks" SubCategory="NewLines" Value="Yes" Levels="Formatter" />
  3. change the param "Value=Yes" to "Value=No"
  4. reload this profile in your IDE using "Profile and Status" option
  5. if necessary, close your IDE and re-open it

Note: you can catch this dialog after this change and closing your IDE!!! Dont worry, just close it!

image.png.8ac367e8c076b7bd1c9ccff2c515070d.png

 

  • now, in your code try this:

...
 var MyVar:string := 'hello world';  // press Ctrl+D to reformat it

 

 

image.thumb.png.704b42fe52747094234ed806d72eea67.png     image.thumb.png.64eebb8aac44a71987e4f970fd154361.png

Edited by Guest

Share this post


Link to post
5 minutes ago, Uwe Raabe said:

The original PDF can be found here

The original PDF has -who know how much- more pages so it's not on the page 71, as I said, it's almost impossible to find his reference after making a slapstick comedy from that document.

Share this post


Link to post
55 minutes ago, joaodanet2018 said:

YES! it's possible do it!

my way around this little obstacle:

  1. go to "Tools -> Language -> Formatter -> Profiles and Status" and save your profile to disk!
  2. open this file and search for:
    1. <Option Name="DelphiFormatter.NewLineForEachVarAndConstElement" Type="Borland.Together.OpenAPI3.Config.LF_CASE" Category="DelphiLinebreaks" SubCategory="NewLines" Value="Yes" Levels="Formatter" />
  3. change the param "Value=Yes" to "Value=No"
  4. reload this profile in your IDE using "Profile and Status" option
  5. if necessary, close your IDE and re-open it

Note: you can catch this dialog after this change and closing your IDE!!! Dont worry, just close it!

image.png.8ac367e8c076b7bd1c9ccff2c515070d.png

 

  • now, in your code try this:

...
 var MyVar:string := 'hello world';  // press Ctrl+D to reformat it

 

 

image.thumb.png.704b42fe52747094234ed806d72eea67.png     image.thumb.png.64eebb8aac44a71987e4f970fd154361.png

Thanks for the large explanation, but did not do the job still...... ;-(( Strange!!

 

  <Option Name="DelphiFormatter.NewLineForEachVarAndConstElement" Type="Borland.Together.OpenAPI3.Config.LF_CASE" Category="DelphiLinebreaks" SubCategory="NewLines" Value="No" Levels="Formatter" />

Share this post


Link to post
Guest

my IDE is RAD 11 and do it!

do you put the "type" in var definition?

 

var VARx : TYPE := value;

Edited by Guest

Share this post


Link to post
1 hour ago, joaodanet2018 said:

my way around this little obstacle:

Ahh, it's you again, emailx45 the warez king and comic book flooder. <o> :classic_cheerleader:

Share this post


Link to post
2 hours ago, emileverh said:

For D11; Can anybody tell me what setting(s) I needin Tools-Options-Language-Formatter ( or may be it's not possible at all ) the format an inline var. I want to have the keyword in front of the variable, now a line break is added. By the way the line break is not added in a 'regular' declaration

 

 

 

Inline variables were introduced with 10.3 back in 2018 and the tooling has not been updated yet to properly support them.  I currently lump them in with GOTO and WITH statements.

 

From my style guide:

 

 

GExperts is the way to go for now.  It would be great to use the built-in formatter and then most of arguments/variances on formatting could be solved by using a shared formatter config file.  (You don't argue, you simply hit CTRL-D, or do it automatically before check-in with the command line tool.) 

Edited by Darian Miller

Share this post


Link to post
1 hour ago, Attila Kovacs said:

Originál PDF má - ktovie koľko - viac strán, takže nie je na strane 71, ako som povedal, je takmer nemožné nájsť jeho referenciu po tom, čo z toho dokumentu urobíte grotesku.

There is content for that.

Share this post


Link to post
Guest

hi @Darian Miller

here in RAD 11 the reformating var inline in same line is working as showed above

Share this post


Link to post
4 hours ago, joaodanet2018 said:

hi @Darian Miller

here in RAD 11 the reformating var inline in same line is working as showed above

There are multiple issues with inline variables... I provided a partial list.  It does work in some cases.

Share this post


Link to post
12 hours ago, joaodanet2018 said:

my IDE is RAD 11 and do it!

do you put the "type" in var definition?

 

var VARx : TYPE := value;

No I did not.... And for me(!) is it not necessary  to include the type

Share this post


Link to post

Yes. There are situations where the compilator doesn't know / cannot determine the data type.

Share this post


Link to post
3 hours ago, Stano said:

Yes. There are situations where the compilator doesn't know / cannot determine the data type.

How do you notice that?! Is the compiler complaining or do you have runtime issues?

Share this post


Link to post

The code does not work. I immediately realized why.
I use TVirtualStringTree (VST). That data is stored in the record. I have it defined as follows

   PTableData = ^ TrTableData;
   TrTableData = record
     Booleans: TList <Boolean>;
     Currencys: TList <Currency>;
     Dates: TList <TDate>;
     Integers: TList <Integer>;
     Others: TList <Variant>;
     Strings: TList <string>;
   end;

For each VST, its structure is different. Some lists will not be created at all. Therefore, the following fails:

var NodeData: = VST.GetNodeData (Node);

It must be

var NodeData: PTableData: = VST.GetNodeData (Node);

 

Edited by Stano

Share this post


Link to post
Guest
21 hours ago, Attila Kovacs said:

Ahh, it's you again, emailx45 the warez king and comic book flooder. <o> :classic_cheerleader:

That insight took quite some time for you. I had you pinned as an observant person. You'll have to work you way up again 🙂

Edited by Guest

Share this post


Link to post
3 minutes ago, Dany Marmur said:

I had you pinned as an observant person.

Haha, thx Dany, I have to admit I'm really busy with other things these days and also, his avatar mesmerizes me all the time I'm seeing it.

But I'll keep an eye on him from now on 😄

Share this post


Link to post
Guest
5 minutes ago, Attila Kovacs said:

Haha, thx Dany, I have to admit I'm really busy with other things these days and also, his avatar mesmerizes me all the time I'm seeing it.

But I'll keep an eye on him from now on 😄

It is enough if you keep an eye on your own posts.

Piece, shalom and salaam, brother! (i am the reporter).

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×