Link to home
Start Free TrialLog in
Avatar of zebada
zebada

asked on

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.
Avatar of Lischke
Lischke

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
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
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
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
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
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
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
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
Avatar of zebada

ASKER

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!
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
Avatar of zebada

ASKER

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.


ASKER CERTIFIED SOLUTION
Avatar of mhervais
mhervais

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zebada

ASKER

Thanks, that's what I needed to know for sure :)

you are welcome zebada :=)