[fpc-pascal] Question on how to avoid memory trouble using FindFirst(), FindNext() and FindClose()

Luiz Americo Pereira Camara pascalive at bol.com.br
Sat Feb 3 19:47:13 CET 2007


Michael Van Canneyt wrote:
>>> All this doesn't exclude that a specialized class may be more suitable for
>>> the job.
>>>       
>> To be honest, the only good point of TStringList seems to be that it is
>> default available on all Object Pascal. The specialised stuff (splitting
>> strings) is also plagued with oddities. (most notably the fact that
>> characters under space are always used as separator)
>>     
>
> Why do you call this oddities ? For GUI programming (and that's what it was
> implemented for) it makes perfect sense.
>   
Early i think that the space issue in DelimitedText was only something 
with very few usages. Later i found that is useless.

Take the following scenario: you want to load a csv into a TStrings.
In TStrings to add a string with space is necessary to enclose it with 
quotes
For example: if you want that the csv string 'aaaa;bb bb;cccc' becomes a 
TStrings with 3 items (aaaa, bb bb and  cccc), is necessary to transform 
'aaaa;bb bb;cccc' into 'aaaa;"bb bb";cccc'
But to do this in a generic way, without knowing if determined value has 
space than you have to parse each item of the csv, check if has space 
and then quote. But in this case is better to add the string directly 
through add method.
>>> I just want to illustrate that, if programmed correctly, TList,
>>> TStringList and friends can still get you a long way...
>>>       
>> I think that the lengths to which people will go to stick to them paints
>> what is needed to make a serious effort to make them legacy.
>>     
>
> I fail to see why, but no doubt you have your reasons. I'd like to see a complete
> list of 'issues' with TStrings (not TStringList, that's just a specific implementation).
>
> Maybe we can then create a TFPStrings which would be interface compatible,
> (in the sense that it can replace TStrings without source changes. It can
> have internal differences, like the space handling) but with a more sensible 
> behaviour ?
>   
Good idea, i think the same.

My issue suggestion is fix the DelimitedText handling space. See above. 
I have a small function that parses csv strings and add to a TStrings 
but uses strutils.posex.
In terms of flexibility, and to comtemple those that want to quote a 
string with space (or whatever) an event can be added to be called at 
each added string though delimitedtext. but since we are talking about 
efficiency i dont think a good idea.

Luiz



More information about the fpc-pascal mailing list