Board index » delphi » formating strings in stringgrid cells - why doesn't this work?

formating strings in stringgrid cells - why doesn't this work?

What am I doing wrong here. I have a stringgrid in which I want to right
justify some of the columns.

As an experiment, if I use:

for loop := 1 to 4 do
cells[1,loop] := format('%8.1f',[strTofloat('12.34')]);

I get a right justified column of 12.3        

If I use the following to convert my real column of values:

cells[1,loop] := format('%8.1f',[strTofloat(cells[1,loop])]);

I get the message "not a floating point number"

(I am using D4 on W95)

--
Keith Howell

 

Re:formating strings in stringgrid cells - why doesn't this work?


Maybe with an intermediate variable ?

...
var    c:string;
....

c:=cells[1,loop];
cells[1,loop] := format('%8.1f',[strTofloat(c)]);

Denis

Re:formating strings in stringgrid cells - why doesn't this work?


I would advise you to do the formatting in the OnDrawCell event.
See the post named "Sv: Can't control cell colors in grid control?" from
03-08-99 for an example of how to use the OnDrawCell event.

Keith Howell <Ke...@ts-space.demon.co.uk> skrev i en
nyhedsmeddelelse:qSf3KDAAnDq3M...@ts-space.demon.co.uk...

Quote
> What am I doing wrong here. I have a stringgrid in which I want to right
> justify some of the columns.

Re:formating strings in stringgrid cells - why doesn't this work?


I already tried that and it gave the same error

In article <HJXp3.10751$V21.340...@nnrp3.clara.net>, Denis Jeanroy
<denj...@claranet.fr> writes

Quote
>Maybe with an intermediate variable ?

>...
>var    c:string;
>....

>c:=cells[1,loop];
>cells[1,loop] := format('%8.1f',[strTofloat(c)]);

>Denis

--
Keith Howell

Re:formating strings in stringgrid cells - why doesn't this work?


In article <qSf3KDAAnDq3M...@ts-space.demon.co.uk>, Keith Howell

Quote
<Ke...@ts-space.demon.co.uk> writes:
>As an experiment, if I use:

>for loop := 1 to 4 do
>cells[1,loop] := format('%8.1f',[strTofloat('12.34')]);

>I get a right justified column of 12.3        

>If I use the following to convert my real column of values:

>cells[1,loop] := format('%8.1f',[strTofloat(cells[1,loop])]);

>I get the message "not a floating point number"

Keith

What is the value of DecimalSeparator (its a Delphi global variable), assign it
to a TLabel.Caption to find out.

I bet it is a comma instead of a full stop. This would be because your PC is
set up for a continental or other country which uses a comma as a
DecimalSeparator.

You can set it to any value for the duration of your program in any early code.

Alan Lloyd
alangll...@aol.com

Other Threads