Recent

Author Topic: In pascal multiple line string possible  (Read 2187 times)

TRon

  • Hero Member
  • *****
  • Posts: 3623
Re: In pascal multiple line string possible
« Reply #15 on: November 28, 2024, 10:00:26 pm »
Unless, of course, somebody would like to argue that comments should be moved out of the unit and into a file of their own?
They should be put in the cloud or better yet, ai generated. Now let's try that with some SQL  :D
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

VisualLab

  • Hero Member
  • *****
  • Posts: 573
Re: In pascal multiple line string possible
« Reply #16 on: November 28, 2024, 10:43:58 pm »
I have inline var syndrome, mind... Silly idiots.

Then are there also smart idiots? :)



I understand your irritation towards Delphi developers. But in Delphi, the following are much more irritating (for example):
  • the crash-prone web installer,
  • the inability to specify the path to the temporary directory for the aforementioned installer,
  • frequent failures of the server that provides installation files to registered users (who paid for Delphi),
  • too few possibilities to customize the IDE (options and settings dialog),
  • very poor IDE documentation in terms of customizing (configuring) your projects, project groups, packages, their library directories for different CPUs and OSs, etc.

I bet these shortcomings are the result of management decisions, not developers.

TRon

  • Hero Member
  • *****
  • Posts: 3623
Re: In pascal multiple line string possible
« Reply #17 on: November 28, 2024, 10:47:10 pm »
Then are there also smart idiots? :)
That is named idiot savant  :)
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

PierceNg

  • Sr. Member
  • ****
  • Posts: 394
    • SamadhiWeb
Re: In pascal multiple line string possible
« Reply #18 on: November 29, 2024, 03:18:47 am »
I understand your irritation towards Delphi developers. But in Delphi, the following are much more irritating (for example):

The most irritating for me (Delphi CE 11 and 12) is the need for my account to be administrator to install/patch Delphi. Not "run as administrator", the account must be administrator. As a non-administrator, I can run Delphi, write programs, but installing patches just goes through the motion and then when I restart Delphi, "patches avaiable".

myisjwj

  • Jr. Member
  • **
  • Posts: 83
Re: In pascal multiple line string possible
« Reply #19 on: November 29, 2024, 03:33:14 am »
temp:=String.Join(sLineBreak, [
'SELECT *',
'FROM Customers',
'WHERE Department = ''Kinglandsoft''',
'ORDER BY Name'
]);

Packs

  • Sr. Member
  • ****
  • Posts: 368
Re: In pascal multiple line string possible
« Reply #20 on: November 30, 2024, 11:45:07 am »
Thank you every one .

Warfley

  • Hero Member
  • *****
  • Posts: 1758
Re: In pascal multiple line string possible
« Reply #21 on: November 30, 2024, 12:21:13 pm »
Delphi 12.0 introduced Multi-line String Literals, for example:

Code: Pascal  [Select][+][-]
  1. const
  2.   MyString = '''
  3.    Line1
  4.    Line2
  5.    Line3
  6.    Line4
  7.  ''';

Maybe FreePascal will add something like this someday.

I personally do not like multi line strings because they break code indentation. I haven't used delphi, if you'd did something like this in python your or C#, each line has a 4 space prefix. So if you want to print the text you first need to do preprocessing of the string to remove those spaces.
The alternative is to write text unindented:
Code: Pascal  [Select][+][-]
  1. const
  2.   MyString = '''Line1
  3. Line2
  4. Line3'''
.
While for like global constants (like i18 strings) this may be acceptable to some degree, having this somewhere in already nested code completely breaks the visual structure of the code.

Packs

  • Sr. Member
  • ****
  • Posts: 368
Re: In pascal multiple line string possible
« Reply #22 on: November 30, 2024, 01:52:44 pm »
in golang

str := `I
am
a
multiline
string`

for sql it should automatically beautify . ie will be great feature 

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11941
  • FPC developer.
Re: In pascal multiple line string possible
« Reply #23 on: November 30, 2024, 02:53:47 pm »
The Delphi case should be refused too...
I have inline var syndrome, mind... Silly idiots.

You mean language design by mob rule ?

Kays

  • Hero Member
  • *****
  • Posts: 613
  • Whasup!?
    • KaiBurghardt.de
Re: In Pascal multiple line string possible
« Reply #24 on: November 30, 2024, 03:10:37 pm »
No, multi‑line strings are by definition not possible. A string is a sequence of char values along one dimension. You can access individual char components with the bracket syntax myStringVariable[123].

A “multi‑line string” proper would mean you could access lines and characters in a line individually, like myStringVariable[lineIndex] would yield one line and myStringVariable[lineIndex][charIndex] would yield a char value within that line.

The only thing that is possible is – as it has been shown – to embed end‑of‑line character sequences within a string, but that does not make the string multi‑dimensional, a data type arranging character sequences into lines. It is still single‑dimensioned.

Code: Pascal  [Select][+][-]
  1. []
  2.   S := 'This is a'            + LineEnding +
  3.        'multiple line string' + LineEnding +
  4.        'in Pascal.';
  5. []
[…]
[…]
NB: This makes the last “line” a degenerate line, an incomplete line. A line is a (possibly empty) sequence of char values (except those of the end‑of‑line character sequence) followed by one end‑of‑line character sequence.
« Last Edit: November 30, 2024, 03:20:31 pm by Kays »
Yours Sincerely
Kai Burghardt

Zoran

  • Hero Member
  • *****
  • Posts: 1882
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: In pascal multiple line string possible
« Reply #25 on: November 30, 2024, 03:57:52 pm »
Lazarus provides a very nice way for entering multiline strings.
Seems that not many people use it just because the name of the menu item in the IDE is not very intuitive.
The details: https://forum.lazarus.freepascal.org/index.php/topic,52669.msg388780.html#msg388780

MarkMLl

  • Hero Member
  • *****
  • Posts: 8029
Re: In Pascal multiple line string possible
« Reply #26 on: November 30, 2024, 04:27:40 pm »
No, multi‑line strings are by definition not possible. A string is a sequence of char values along one dimension.

Yes, and once you've progressed beyond punched cards and mainframe fixed-length records an EOL is just an embedded character.

At that point you either need some internal convention to quote it (e.g. implicit concatenation where quoted strings are separated only by whitespace), an escaping mechanism (e.g. \ ) or a convention that results in an internal EOL being interpreted as part of the string rather than dividing multiple lines of sourcecode.

There's been conventions for embedding SQL etc. in sourcecode since the 1980s. It's high time that Pascal woke up to the fact.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 16177
  • Censorship about opinions does not belong here.
Re: In pascal multiple line string possible
« Reply #27 on: November 30, 2024, 04:46:56 pm »
Well:
https://gitlab.com/freepascal.org/fpc/source/-/issues/35827
tested and works.
If I want it? No, but it works and as I wrote before, the code is available but not applied.
(you need to patch your own compiler version)

It seems several people have been sleeping for a couple of years.
Quote
No, multi‑line strings are by definition not possible.
is talking nonsense.
Note the Delphi syntax is, however horrid, slightly more elegant.

That patch could be applied with the same syntax '''
« Last Edit: November 30, 2024, 05:02:59 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Tony Stone

  • Full Member
  • ***
  • Posts: 234
Re: In pascal multiple line string possible
« Reply #28 on: November 30, 2024, 05:09:27 pm »
Lazarus provides a very nice way for entering multiline strings.
Seems that not many people use it just because the name of the menu item in the IDE is not very intuitive.
The details: https://forum.lazarus.freepascal.org/index.php/topic,52669.msg388780.html#msg388780




WHAT THE HECK!  I knew a while back I saw something in Lazarus to edit multi line strings!  A couple weeks ago I really needed it so I wrote my own tool!!  Dam it.  WHAT A HORRIBLE NAME!!! I looked through the IDE for a good 10 minutes looking for it then gave up to write my own. lol!

Here is what I wrote... kind of useless now haha https://github.com/TonyStone31/Pascal-MultiLine-String-Helper  (oh well... was kind of fun to cobble together)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5755
  • Compiler Developer
Re: In pascal multiple line string possible
« Reply #29 on: November 30, 2024, 06:08:21 pm »
There is actually a patch for that, that I tested and confirmed to work, but it used back-ticks..

Which visually is probably not a bad choice: sequences of '""' etc. "get old fast".

I know that the core team is inclined to tell us to put multilines into resource files, but I maintain- impenitently and from experience- that they are wrong. If you're writing Pascal code that relies on- for example- an SQL fragment, the place to put that fragment is adjacent to the associated Pascal: and that's also the place to put the comments explaining what the combination is doing.

Unless, of course, somebody would like to argue that comments should be moved out of the unit and into a file of their own?

Comments and embedded fragments of other languages are different things, the former are part of the language, the later are simply strings from the language's point of view.

For code fragments moving them to a separate file has the advantage that an IDE can easily syntax highlight them or provide refactoring features. With code embedded as part of other code this becomes harder.

 

TinyPortal © 2005-2018