Recent

Author Topic: [SOLVED] What's the problem with this?  (Read 2571 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1300
[SOLVED] What's the problem with this?
« on: August 27, 2018, 11:22:49 am »
I'm trying to use TStringHelper.split, but ExcludeEmpty is not identified.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   s: string;
  4.   slist: array of string;
  5.   ti : integer;
  6. begin
  7.    s := '$3$5$8';
  8.    slist := s.split(['$'], ExcludeEmpty);  // this form is found in Delphi manual.
  9.    slist := s.split(['$'], [ExcludeEmpty]);    // but neither works
  10.  
  11.    for ti := 0 to High(slist) do
  12.       memo1.lines.add(slist[ti]);
  13.    Finalize(slist);
  14. end;          

BTW, should I write Finalize(slist) here?
« Last Edit: August 27, 2018, 11:58:03 am by egsuh »

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: What's the problem with this?
« Reply #1 on: August 27, 2018, 11:31:19 am »
It should be defined in unit SysUtils (see: https://www.freepascal.org/docs-html/rtl/sysutils/tstringsplitoptions.html).

Bart

rvk

  • Hero Member
  • *****
  • Posts: 6171
Re: What's the problem with this?
« Reply #2 on: August 27, 2018, 11:50:45 am »
Using this it works fine:
Code: Pascal  [Select][+][-]
  1. slist := s.split(['$'], TStringSplitOptions.ExcludeEmpty);

ExcludeEmpty is defined with SCOPEDENUMS ON.
Code: Pascal  [Select][+][-]
  1. {$SCOPEDENUMS ON}
  2.   TStringSplitOptions = (None, ExcludeEmpty);
  3. {$SCOPEDENUMS OFF}
  4.  
So you need to use TStringSplitOptions.ExcludeEmpty.
« Last Edit: August 27, 2018, 11:52:22 am by rvk »

egsuh

  • Hero Member
  • *****
  • Posts: 1300
Re: What's the problem with this?
« Reply #3 on: August 27, 2018, 11:57:48 am »
Alright. Thank you for your help.

Thaddy

  • Hero Member
  • *****
  • Posts: 14393
  • Sensorship about opinions does not belong here.
Re: [SOLVED] What's the problem with this?
« Reply #4 on: August 27, 2018, 12:29:42 pm »
I explained in the code I added to a previous question: note the remark about scoped enum...
http://forum.lazarus.freepascal.org/index.php/topic,42351.msg295482.html#msg295482.
« Last Edit: August 27, 2018, 12:32:14 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018