Recent

Author Topic: Little bit...  (Read 2714 times)

mas steindorff

  • Hero Member
  • *****
  • Posts: 576
Re: Little bit...
« Reply #15 on: April 19, 2026, 02:03:39 am »
thanks, that clears thing up for me.  I tend to think of strings as something complex (managed) so I've avoid them as variants.  It makes since they would be safe to pass as a const if you are not modifying them.
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

Thaddy

  • Hero Member
  • *****
  • Posts: 19129
  • Glad to be alive.
Re: Little bit...
« Reply #16 on: April 19, 2026, 07:07:38 am »
Just looking for some more info...
1: Are you saying .Add with 2 parameters will automatically use the 1st as a format string?  (The TStringList document doesn't say anything about this)

2: I can say I've ever passed a string to a procedure in an "array of const". Is this something newly added after FPC 3.2 or have I missed out in my studies? 
MAS
1. No, I introduced a property and a new add that calls inherited add with the value of the property. So you can leave the Fmt parameter out if the property is set. I must say, I did not even know that the direct Format() syntax was supported by TStringlist. It is a feature of TStrings.
I found that out when I accidentally left the format keyword out and that worked to my surprise.

2. No, this is really old. Even TP knows it. Basically look at it as an array of variants that are internally solved by the compiler to their true type. Many languages and OS's have a similar feature. (Windows has it in kernel32)
It is pascal's equivalent of a variadic array.

3. yes  :D :D , me too :D :D

The documentation says:
https://www.freepascal.org/docs-html/rtl/classes/tstrings.add.html
« Last Edit: April 19, 2026, 07:27:15 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

ASerge

  • Hero Member
  • *****
  • Posts: 2492
Re: Little bit...
« Reply #17 on: April 19, 2026, 07:15:23 am »
You can simply add a formatstring property...


...
Did you make a mistake with the topic? Here's about the delimiters. About formatting in the adjacent topic.

Thaddy

  • Hero Member
  • *****
  • Posts: 19129
  • Glad to be alive.
Re: Little bit...
« Reply #18 on: April 19, 2026, 07:28:48 am »
I guess so, but I picked it up from this thread.
Put on the wrong foot by the linebreak #36 shenanigans.
« Last Edit: April 19, 2026, 07:36:40 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

egsuh

  • Hero Member
  • *****
  • Posts: 1790
Re: Little bit...
« Reply #19 on: April 21, 2026, 05:05:41 am »
@ASerge,
Quote
    L.QuoteChar := #0;

Thank you for this, but what I want is 3 lines consistently.

I'm thinking over this issue becuase the line breaks within a single string of TStrings are broken when copied to another TStrings.

Code: Pascal  [Select][+][-]
  1.    Stringlist1.Add('Hello, '#13#10'World');  // this gives stringlist1.count = 1.
  2.    StringList2.Text := StringList1.Text;     // then StringList2.count = 2
  3.  
And with commatext or delimitedtext, delimiter or quotechar themselves (and line breaks) may be included within a string.

If everything is done within program, then I can do anything. But my app has to receive "inputs" from ordinary users. They can use single quote, double quote, slash, backslash, comma, and whatever.

So my tentative conclusion is using control characters. Well, somebody might type Alt-31. But It's probability seems very low.

Code: Pascal  [Select][+][-]
  1.     StringList1.LineBreak := #31;
  2.     StringList1.LineBreak := #31;
  3.  
  4.     StringList2.Text := StringList1.Text;     // this gives consistent results
  5.  

Anyway thank you for all the comments. I had time to think over how splitting works. I should have been more specific. But the issue is not simply treating inputs from users of my app. With database structuer, I designed one to many relation DB structure, like

Master table :
         id         integer
         Name   string

Slave table
         id                         integer
         property_name     string
         property_value     blob
         property               blob computed by (property_name || '=' || property_value)


Here the property_value itself is a blob type, which may contain all the white characters and quote characters.

And I want single record for one person, with property field containing all property_name=property_value pairs as a blob field.
The SQL looks like:

Code: SQL  [Select][+][-]
  1.   SELECT m.id, name, properties  
  2.        FROM master m
  3.        LEFT JOIN
  4.             (SELECT id, list (property, ascii_char(31)) AS properties FROM slave
  5.                      WHERE id=:id
  6.                       GROUP BY id)  s
  7.              ON m.id=s.id
  8.        WHERE id=:id
  9.  


And then I can use TStrings to process the properties.


Code: Pascal  [Select][+][-]
  1.      StringList1.LineBreak := #31;
  2.      StringList1.Text := SQLQuery1.FieldByName('properties').AsString;
  3.  
  4.      age := StrToInt(StringList1.Values['age']);
  5.  


Thaddy

  • Hero Member
  • *****
  • Posts: 19129
  • Glad to be alive.
Re: Little bit...
« Reply #20 on: April 21, 2026, 01:24:47 pm »
Remember that #13 means a carriage return and #10 means a line feed.
If you know from old school type writers (maybe, depends on age), you will know that a new line is added anyway.

Ping!, they did - my case do, because I have a working very old one from 1932 -  even old ones from the early 1900's.

Off topic: Ribbon cassettes are still available - when dried out or damaged -and/or re-inkable for most common German or American brands. There is quite some community world wide for these old beasts.
« Last Edit: April 21, 2026, 01:35:14 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

ASerge

  • Hero Member
  • *****
  • Posts: 2492
Re: Little bit...
« Reply #21 on: April 21, 2026, 09:51:32 pm »
Code: Pascal  [Select][+][-]
  1.    Stringlist1.Add('Hello, '#13#10'World');  // this gives stringlist1.count = 1.
  2.    StringList2.Text := StringList1.Text;     // then StringList2.count = 2
  3.  
TStringList.SkipLastLineBreak

 

TinyPortal © 2005-2018