TStringList - No blanks and no spaces allowed?

Howdi gang

I'm using a TStringList in one of my servers for passing data around. It's 
ideal for me to use simply because of the values property which allows my 
program to set and find data / objects with ease.

Anyway turns out the little critter doesn't allow you to set it's string 
with spaces and it doesn't like blanks either.

Now whats wrong with me doing this?:

var
SList: TStringList;
begin
SList.Values['Test'] := ''; //Doesn't work
SList.Values['This'] := 'out here';  //Also doesn't work
end;

Now why would anyone impose such a stupid limitation that will screw that 
up? If I want to set a string with spaces, why is this a problem? The help 
file says that this format is the same as a windows ini file.. and even 
those have a carriage return at the end of each line!

So.. how does one get around this problem? I'm using this in a TCP client / 
server in order to form data packets and them sending the SList.Text 
property so that it all goes down the wire at once. The snag is that with 
the above fault, i can't send blank datafields or anything with spaces 
unless i base64 encode it (which doesn't work well for blank strings). Thats 
not such a big problem but then it means i need to do it manually for every 
lot of data sent or received! I did mull over creating a descendant class 
but it appears that the limitation is so deep rooted that i'd never be able 
to dig it out / override it.

Is there a 3rd party equivalent or hack that does away with this pain of a 
limitation?

JC
0
Justin
1/16/2015 1:07:45 AM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

3 Replies
2957 Views

Similar Articles

[PageSpeed] 46

> {quote:title=Justin Case wrote:}{quote}
> Howdi gang
> 
> I'm using a TStringList in one of my servers for passing data around. It's 
> ideal for me to use simply because of the values property which allows my 
> program to set and find data / objects with ease.
> 
> Anyway turns out the little critter doesn't allow you to set it's string 
> with spaces and it doesn't like blanks either.
> 
> Now whats wrong with me doing this?:
> 
> var
> SList: TStringList;
> begin
> SList.Values['Test'] := ''; //Doesn't work
> SList.Values['This'] := 'out here';  //Also doesn't work
> end;
> 
> Now why would anyone impose such a stupid limitation that will screw that 
> up? If I want to set a string with spaces, why is this a problem? The help 
> file says that this format is the same as a windows ini file.. and even 
> those have a carriage return at the end of each line!
> 
> 
> JC

{code}
var
  SList: TStringList;
begin
  SList: TStringList.create; //You really need this bit
  SList.Values['Test'] := ''; //Doesn't work - Yes it deletes the key 'Test'
  SList.Values['This'] := 'out here';  //Also doesn't work - Yes it does
end;
{code}

'' deletes an existing key value pair so maybe have a special sequence for blank I use '_B_l_a_n_k_'
{code}
var
  SList: TStringList;
  procedure SetVal( _key, _val : string );
  begin
     if _val.IsEmpty then
       SList.Values[ _key, '_B_L_a_N_K_' );
     else
       SList.Values[ _key,_val  );
  end;

begin
  SList: TStringList.create; 
  SetVal( 'Test', ''); 
  setVal( 'This', 'out here' );  
end;
{code}

Space in the string works fine for me !!!




--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
0
Linden
1/16/2015 1:49:30 AM
<Linden ROTH> wrote in message news:709686@forums.embarcadero.com...
>  SList: TStringList.create; //You really need this bit

Yes in my hasty rush to make this thread i didn't bother including that (but 
rest assured it is in my code)

>  SList.Values['Test'] := ''; //Doesn't work - Yes it deletes the key 
> 'Test'

Which is annoying for me.

>  SList.Values['This'] := 'out here';  //Also doesn't work - Yes it does

Not in D6 it doesn't! Believe me.. i spent hours chasing my tail round on 
this.

From the help file:

property Values[const Name: string]: string;
<snip>
The Name that identifies the string is to the left of the equal sign (=), 
and the current Value of the Name identifier is on the right side. There 
should be no spaces present before or after the equal sign.

No spaces before or after the equals sign - and after is the problem I am 
having. I suppose i could replace spaces with [space] but then i'd need to 
do that / check that for everything. There must be a better way?

> Space in the string works fine for me !!!

This annoying 'feature' must have been changed in later versions of delphi.
0
Justin
1/16/2015 2:14:42 AM
Justin wrote:

>> SList.Values['Test'] := ''; //Doesn't work - Yes it deletes the key 'Test'
>> 
> Which is annoying for me.

That behavior is by design.

If you want to store a blank string and still be able to access it by Name, 
you can do this instead:

{code}
I := SList.IndexOfName('Test');
if I = -1 then
  SList.Add('Test=')
else
  SList.Strings[I] := 'Test=';
{code}

>> SList.Values['This'] := 'out here';  //Also doesn't work - Yes it does
>> 
> Not in D6 it doesn't! Believe me.. i spent hours chasing my tail round
> on this.

I use BCB 6 (which uses the same VCL/RTL as Delphi 6) every day at my day 
job.  Trust me, the Names[] and Values[] properties happily accept strings 
with spaces in them.  It is only when assigning a blank string to the Values[] 
property that you run into a problem (and only if you want to keep the Name 
in the list).

> From the help file:

Read it again more carefully.  When you use the Values[] property, it works 
with strings that are stored in 'Name=Value' format in the list.  The portion 
of the documentation that you quoted is referring to the **entire 'Name=Value' 
string as a whole**, not the Name or Value sub-portions.

For instance:

{code}
SList.Values['This '] := 'that'; // string stored is 'This =that'
SList.Values['This'] := ' that'; // string stored is 'This= that'
SList.Values['This '] := ' that'; // string stored is 'This = that'
{code}

That being said, the documentation says **should**.  The above actually works 
as shown.  The Names[] and Values[] properties look for just the '=' by itself, 
treating everything before it (spaces and all) as a Name, and everything 
after it (spaces and all) as a Value.  There is no trimming involved.  Look 
at the RTL's source code for TStrings in Classes.pas and you will see this 
to be true.

> No spaces before or after the equals sign - and after is the problem I
> am having.

No, it is not.  You are having a problem with blank strings, not strings 
with spaces in them.

> I suppose i could replace spaces with [space] but then i'd need to
> do that / check that for everything. There must be a better way?

No, you do not need to resort to that extreme.

> This annoying 'feature' must have been changed in later versions
> of delphi.

Nope.  It has always worked this way, in every version.  The only change 
that has been made is the introduction of the NameValueSeparator and ValueFromIndex 
properties in Delphi 7.

--
Remy Lebeau (TeamB)
0
Remy
1/16/2015 2:53:35 AM
Reply:

Similar Artilces:

ALLOW ALLOW ALLOW
Name: Sara F Product: Firefox Summary: ALLOW ALLOW ALLOW Comments: It's getting extremely tiresome to have to "allow" a site to reload/redirect all the time. at least three of my favourite sites require that I do this, including my webmail, which often does it TWICE. Also, should I not select the 'allow' option and switch tabs, the option disappears entirely, which means I have to reload the page and repeat the whole process. My suggestion is this: Invest some time into "allowing" Firefox to REMEMBER which sites I always allow. Browser ...

allowing postcodes without a space (as well as with a space)
Hi Guys, I have this validation script that checks the postcode. At the moment however it does not allow a user to enter the postcode without a space in it.(GIR 0AA|[A-PR-UWYZa-pr-uwyz]([0-9]{1,2}|([A-HK-Ya-hk-y][0-9]|[A-HK-Ya-hk-y][0-9]([0-9]|[ABEHMNPRV-Yabehmnprv-y]))|[0-9][A-HJKS-UWa-hjks-uw]) [0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2})  Thanks alexASP.NET: Hi Guys, I have this validation script that checks the postcode. At the moment however it does not allow a user to enter the postcode without a space in it. (GIR 0AA|[A-PR-UWYZa-pr-uwyz]([0-9]{1,2}|([A-HK-Ya-hk-y][0-9]|[A...

delphi.general
Sorry if this is "out of topic"! but since some days ago I can't read the group *embarcadero.public.delphi.language.delphi.general* Does anybody know if there's something wrong with it? Or maybe is my reader? (Thunderbird) I get this messagge when I try to read the latest messages: Error! newsgroup server responded:no such article found Perhaps the article has expired <692702@forums.embarcadero.com> (33145) Click here to remove all expired articles sergio wrote: > Sorry if this is "out of topic"! but since some days ago I can'...

allow or not to allow
sygate personal pro asks if I want netbeui.vxd and Win 32 Kernel core component to access the internet-since I do not know what these programs are, can someone advise why these programs want to access the net and what they do------------thanxxxxxxx--- t <me@anon.com> wrote: > sygate personal pro asks if I want netbeui.vxd and Win 32 Kernel core > component to access the internet-since I do not know what these programs > are, can someone advise why these programs want to access the net and what > they do------------thanxxxxxxx--- I don't use Sygate (its support...

Blank Space
i am using crystal report viewer control of asp.net, and using report,page header,detail,group sections. All is fine data loaded successfully but between last entry of requested data and page footer too many blank space, i need that page footer shown exactly after data. Note that i drilldown and suppress group footer,report footer but still problem, please ask me what can i do....

blank space
Name: giantjoebot@hotmail.com Email: giantjoebotathotmaildotcom Product: Minefield Summary: blank space Comments: there is a big blank space after the minefield drop down menu. You should combine that with the tabs to save space. Browser Details: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.0b8pre) Gecko/20101201 Firefox/4.0b8pre From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

space blanks
Mr. I need to control the spaces in target between two or but words, example: xxxxbbxxxbxxxx, where b=space in target and x = word, only must exist a space between each word. thank you very much. Take a look at the examples for the Replace function in Help. You will be finding and replacing two spaces with one space. "jquexada" <jquexada@gmail.com> wrote in message news:6414bc2e-033d-46f1-bf0c-8edd20a9a241@d61g2000hsa.googlegroups.com... > Mr. > I need to control the spaces in target between two or but words, > example: xxxxbbxxxbxxxx, where b=space in t...

blank space
--____FEXQJEYFPASGUNAEOYDG____ Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; modification-date="Sat, 20 Feb 2009 09:35:57 -0600" In the above picture I circle a blank space in the client settings. = Computers that have this blank have login problems with drive script = mapping errors. If I remove it and reboot the computer the problem is = gone. Does anyone know what could cause this blank entry. I have had this = 4.91 sp 2,3,4. Scott E. Malugin A+ Certified NetWork+ Certified Dickson C...

What generals generally do
Reading a McChrystal thread elsewhere, I came across someone quoting a US general http://en.wikipedia.org/wiki/Smedley_Butler > I spent 33 years and four months in active military service and > during that period I spent most of my time as a high class thug for > Big Business, for Wall Street and the bankers. In short, I was a > racketeer, a gangster for capitalism. I helped make Mexico and > especially Tampico safe for American oil interests in 1914. I helped > make Haiti and Cuba a decent place for the National City Bank boys to > collect revenues in. I ...

Need to get number of charictors to the first blank (white space) space
------_=_NextPart_001_01C6447F.94401231 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Lets say that I have a variable; =20 My $test =3D "asdfjaslfkjasdf lksaflksajfalksjf fsalkjsaflkjsafd fajd alsjfk"; =20 I want a way to count the number of characters to the first space. Is there an easy function to do this??? =20 =20 Thanks =20 Tim ------_=_NextPart_001_01C6447F.94401231-- Have you seen the length() function? perldoc -f length If you use a pattern match to grab all of the charac...

Need help to allow a working Delphi 3 project to build on Delphi XE
How do I adjust this working Delphi 3 program that uses OLEAUTO and OLE2 to work on the newer Delphi XE, Program code is below this, errors are here : Checking project dependencies... Compiling admn_api.dproj (Debug, Win32) dcc command line for "admn_api.dpr" c:\program files (x86)\embarcadero\rad studio\8.0\bin\dcc32.exe -$O- -$W+ --no-config -M -Q -AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE; DbiProcs=BDE;DbiErrs=BDE -DDEBUG -I"c:\program files (x86)\embarcadero\rad studio\8.0\lib\Win32\release";"C:\Users\Administrator\Documents\RAD Studio...

Macro to delete Blank rows in excel sheet (including check for blank spaces)
Hi all, I tried to google alot for deleting blank rows from excel sheet which was used by my asp.net appluication to display the data in grid... after struggling alot for the same i developed a code in VBA to delete blank rows in excel sheet and i called it on save event of the same... So below is the code to delete blank rows that is called when we try to save the excel sheet... You can use the same code to be called either on Open event or on close event---for this what you need to do is just create a new function named Auto_Open (Called when you open the exce...

Suppressing Blank Space
Hi I am trying to suppress blank space in infomaker 10.5 I looked at the documentation and it said to auto size height on all columns above. I did all of this and changed the slide up option. This does not show in the "preview" of the report. I also tried reopening and nothing. Any suggestions? Thanks Joe slide up directly or all? directly above looks at anything that would get hit by the object below if it slides up. all means it looks at all objects above it. <J Nap> wrote in message news:48220d57.52ae.1681692777@sybase.com... > Hi > I am trying ...

Web resources about - TStringList - No blanks and no spaces allowed? - embarcadero.delphi.general

Comparison of programming languages (string functions) - Wikipedia, the free encyclopedia
String functions are used in computer programming languages to manipulate a string or query information about a string (some do both). Most ...

Bitwise Magazine :: Chrome - marc hoffman interview
Bitwise Magazine :: the free online magazine for programmers and technical users

Issues - dwscript - Delphi Web Script general purpose scripting engine - Google Project Hosting
My favorites ▼ - Sign in dwscript Delphi Web Script general purpose scripting engine Project Home Downloads Wiki Issues Source New issue Search ...

Comparison of programming languages (string functions) - Wikipedia, the free encyclopedia
String functions are used in computer programming languages to manipulate a string or query information about a string (some do both). Most ...

Resources last updated: 11/26/2015 2:17:14 PM