What is the datatype of the underlying database field for the
field named tblClientPrice?
My guess is that it's some kind of "number" and probably
this means the component will call the StrToFloat function
to covert the new "text" to the internal float value
>From the help StrToFloat (about coverting a string S):
" S must consist of an optional sign (+ or -), a string of digits
with an optional decimal point, and an optional mantissa.
The mantissa consists of 'E' or 'e' followed by an optional sign (+
or -) and a whole number. Leading and trailing blanks are ignored."
I see 3 possible problems with what you have here.
1. If the field is null, text will be '' and you will try to assign
the new value '+ ' to it - which doesn't fit the rule above.
2. If the field has a negative value (say -123.45) - text will
already have a preceding minus sign. You will attempt to
assign the new value '+ -123.45' - also violating the format rule
above.
3. Even if the field has non-negative value (say 123.45) your new
text value will be '+ 123.45' - also violating the rule because of
the blank.
You can fix up #3 here by tacking on '+' instead of '+ ' (remove the
trailing blank) but you still have 1 & 2 to worry about.
But finally - I am missing the whole point of the '+' here.
When you assign to text properties of fields with floating point
values, the component will immediately convert your text to the
underlying value. If you then turn around and look at the text
property, it will be the result of converting the value back into
a string. So your sign won't be there. So I don't understand
the purpose of the trick with the plus sign.
-ns
----- Original Message -----
From: "John Christenhusz" <[EMAIL PROTECTED]>
To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
Sent: Wednesday, August 15, 2001 5:09 AM
Subject: [DUG]: TwwdbGrid
> Hi folks,
>
> I want to change the text in a TwwdbGrid for a particular item. The
> following code doesn't work:
>
> procedure TformREDB.dbgridSearchCalcCellColors(Sender: TObject; Field:
> TField;
> State: TGridDrawState; Highlight: Boolean; AFont: TFont; ABrush:
> TBrush);
> begin
> if (field.name = 'tblClientPrice') and (tblClientType.asInteger = 2)
> then
> field.text := '+ ' + field.text;
> end;
>
> It generates the following error: '+ ' is not a valid floating point
> value for field 'Price'
>
> Any ideas how to solve this problem?
>
> TIA
>
> John.
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/