TStrings.CommaText Bug???

If x is of type TStrings and I do this:

x.CommaText := 'A,B,,D,E';

I would expect x to contain the following strings:
'A'
'B'
''
'D'
'E'

But it actually contains:
'A'
'B'
'D'
'E'

Is this a bug? And what is the workaraound?

This is not how the doco describes CommaText's behaviour.
LVL 6
zebadaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Hi zebada,

I tried out what you have described and got exactly what you and I had expected. Do your really use 'A,B,,D,E' or is this rather a simplification of another string you actually assign to CommaText?

What version of Delphi are we talking about?

Ciao, Mike
0
kotikCommented:
Hi, zebada,

I used that many times and it works perfect. I think that Lischke is right, maybe something wrong with the string itself.
I use Delphi 4.

Regards,
Kot
0
mhervaisCommented:
Zebada I just tried it and it and it works fine :

procedure TForm1.FormCreate(Sender: TObject);
var
  mytext : string;
  i : integer;
  s : string;
begin
  MYstrings := TStringList.Create;
  MyStrings.CommaText := 'A,B,,D,E';
  mytext := MyStrings.CommaText;
  for i := 0 to MyStrings.Count - 1 do
  begin
    s := mystrings.Strings[i];
  end ;
  MyStrings.Free;
end;

I get it back in a string (mytext) or by reading them individually.

The only thing is that you must use TStringList instead of Tstrings.

regards Marc
0
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

mhervaisCommented:
if it is a matter of a bug in your vesion of delphi, you will have to inherit the TStringList Component, in order to override the CommaText Property.

Regards, Marc
0
kotikCommented:
Marc!
The CommaText property of the TStringList class is inherited from the TStrings and there is no difference in assigning TStringList.CommaText or TStrings.CommaText.

Regards,
Kot
0
mhervaisCommented:
KOT Not in my version of Delphi.
When I do it with my version of Delphi 4 V3(french version) I get an EAbstract Error with TStrings at Runtime

regards, Marc
0
kotikCommented:
Marc,
I ment only that there is no difference in the CommaText property.
But of course you'll get EAbstract Error because the TStrings is an abstract class and cannot be used directly.

Regards,
Kot
0
kotikCommented:
Marc,
I ment only that there is no difference in the CommaText property.
But of course you'll get EAbstract Error because the TStrings is an abstract class and cannot be used directly.

Regards,
Kot
0
zebadaAuthor Commented:
OK, I think I mis-represented the question.

The exact "test" code was:

Assuming a string grid control called StringGrid1 is on the form....

StringGrid1.Rows[0].CommaText := 'A,B,,D,E';
ShowMessage(StringGrid1.Rows[0].CommaText)';

Go figure!
0
mhervaisCommented:
here is how to dood it :

  StringGrid1.Rows[0].CommaText := 'A,B," ",D,E';
  ShowMessage(StringGrid1.Rows[0].CommaText);

I think the commatext function has nothing to do with it. It is the TStringGrid that will not accept creating columns like that with an empty string. replace it with a space, and it will work all right.

regards Marc
0
zebadaAuthor Commented:
I'm not rejecting this because its wrong, the work-around you propose is right on the money.

I would just like to try to clear this up:

Why does the TStrings.CommaText method behave differently to TStringGrid.CommaText method.


0
mhervaisCommented:
I repeat :

If you look to the VCL source, you will see that There is no special implementation in TSTringsGrid for Commatext. On the contrary, it is the TStrings Method that is being used.

Therefore the different behaviour comes from the implementation of TStringGrid, that refuses to create a column with an empty String, and that begins to discard such items then the list that was created by CommText.

regards Marc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zebadaAuthor Commented:
Thanks, that's what I needed to know for sure :)

0
mhervaisCommented:
you are welcome zebada :=)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.