Recent

Author Topic: [SOLVED] How to best enable users to define their preferred delimiter?  (Read 711 times)

Gizmo

  • Hero Member
  • *****
  • Posts: 831
I know theres lots of posts about delimitedtext, but I'm trying to work out the best way to allow my users to specify their preferred character via the interface, and I am not using a StringList, as referenced here (https://www.freepascal.org/docs-html/rtl/classes/tstrings.delimitedtext.html).

So for example, currently, I use

Code: Pascal  [Select][+][-]
  1. 'my string' + ',' + 'more of my string';
  2.  

to place delimiters.

So I have set a labelled edit field in the GUI now. If the user wants to use ',' or ':' or any other printable character, I can use leDelimiterField.Text instead of ','.

Code: Pascal  [Select][+][-]
  1. 'my string' + leDelimiterField.Text + 'more of my string';
  2.  

I also notice it has .Text.IsDelimiter() but I am not quite sure how to use that in this context. I notice there is also TStringHelper.Split (https://www.freepascal.org/docs-html/rtl/sysutils/tstringhelper.split.html) but again, I think it needs to be told what the delimiter character is, and I want my users to be able to choose that themselves.

Lets say the user wants to use tab (#9). So they enter the tab value of '#9' in the label edit field. If I use the text property still as above, then '#9' understandably gets inserted into the output string. And I'd prefer not to run a conversion routine for what might be millions of lines on that GUI element every time. I want to rapidly "set" the chosen delimiter when the user clicks a button (and I have that set to a comma currently but the user could choose ':' or tab) such that for every line thereafter that character is chosen, regardless of whether it is an ASCII selected value, or a non printable one like tab.

In other words, what I need to do is

1) User chooses a character, such as ':' or tab (#9) in the edit field
2) When user clicks button, program "gets" the chosen delimiter and sets it as ChosenDelimiter
3) For every string thereafter requring delimiter,  ChosenDelimiter is used, whether it be printable ASCII, or not (i.e. tab)

How best might folks approach this? Is there a more suitable method than what I am doing here?

« Last Edit: May 03, 2021, 03:52:22 pm by Gizmo »

Zvoni

  • Hero Member
  • *****
  • Posts: 2330
Re: How to best enable users to define their preferred delimiter?
« Reply #1 on: May 03, 2021, 03:19:54 pm »
How about offering the User a ComboBox in ListStyle with the "usual" delimiters (incl. non printable)?
That way you could catch the chosen delimiter and process it (if it's a non-printable like TAB)
You could still offer an additional field "custom delimiter".
In that case all gloves would be off, and the user is completely responsible for the results
Of course you would have to sanity check the ComboBox against the Custom Delimiter (e.g. If something is entered in Custom Del ignore ComboBox and vice versa)
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: How to best enable users to define their preferred delimiter?
« Reply #2 on: May 03, 2021, 03:52:12 pm »
Yes, good shout! That is much better.

So I have solved this using a combo box, with ',', ':' and 'Tab' as 3 options. Then I use it like this :

Code: Pascal  [Select][+][-]
  1. ChosenDelimiter := C2FDelimiterComboBox.Text;  // if its anything except Tab, just use it
  2.   if ChosenDelimiter = 'Tab' then                          // Or if it is tab, use #9
  3.   begin
  4.     ChosenDelimiter := #9;
  5.   end;              
  6.  

And I've set ChosenDelimter as a public var for the form.

Thanks man, and anyone else who reads.

 

TinyPortal © 2005-2018