Seeing as no-one more knowledgable has answered yet, here is my best
guess. Hopefully it gets you on the right track. Not complete, and could
be wrong.
TFormatSettings is a record, and NegCurrFormat is a field of that
record. The NegCurrFormat that you are passing is a global environment
variable, not a TFormatSettings. You should be setting the NegCurrFormat
field of your TFormatSettings record, then passing in the whole record.
More correct syntax for using it is below. Incidently, this code doesn't
work, but maybe it will help you work out how to do it. I think I am
missing where to get the initialising locale ID from, and also I am
probably not picking the right values for the fields of my
TFormatSettings record correctly.
procedure TForm1.btn1Click(Sender: TObject);
var
price: Double;
str: string;
format: TFormatSettings;
begin
GetLocaleFormatSettings(SysLocale.DefaultLCID ,format);
format.NegCurrFormat := 1;
format.CurrencyFormat := 0;
format.CurrencyString := '$';
format.CurrencyDecimals := 2;
format.DecimalSeparator := '.';
price := StrToFloat('-$2.50',format);
end;
It just happens (from the help also) that you also need to initialise
your TFormatSettings by calling GetLocaleFormatSettings before using it.
Also, I am unsure where you get the windows locale ID that you are
supposed to pass to GetLocaleFormatSettings from (SysLocale.DefaultLCID
is a guess, and not a good one).
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Mark Howard
Sent: Tuesday, April 27 2004 3:11 p.m.
To: [EMAIL PROTECTED]
Subject: [DUG] StrToFloat
Hi All
I want to be able to convert a string to floating point where the string
is in the form
either $245.45
OR -$242.45
The first one converts OK but the second one come up with "-$242.45 is
not a valid
floating point value.
The Delphi help says:
"Category
floating point conversion routines
Delphi syntax:
function StrToFloat(const S: string): Extended; overload;
function StrToFloat(const S: string; const FormatSettings:
TFormatSettings):
Extended; overload;"
AND
"Delphi syntax:
type
TFormatSettings = record
CurrencyFormat: Byte;
NegCurrFormat: Byte;
ThousandSeparator: Char;"
But if I use
StrToFloat('-$242.45', NegCurrFormat)
I get a message saying "there is on overloaded version of StrToCurr that
can be
used with these arguments."
Is someone able to help, please?
TIA
Mark
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi