Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Nov : How to use NUMBERFMT with GetNumberFormat function

www.cryer.info
Managed Newsgroup Archive

How to use NUMBERFMT with GetNumberFormat function

Subject:How to use NUMBERFMT with GetNumberFormat function
Posted by:"Jan" (jva..@thevagabonds.com)
Date:Fri, 30 Nov 2007 12:25:02

Need some help setting up the pointer.  How can we set up NUMBERFMT
parameter in order to pass it to the GetNumberFmt function?  I need to
change the number of digits after the decimal for the specified locale.

I've tried several methods of setting up the type and pointer.  Here's what
I'm trying at the moment (no it's not the best attempt but gives you the
idea).  At runtime an error is returned saying the parameter is incorrect:

function TForm1.OverrideFixedFormat(LocaleID : LCID; Value:
string;NumDigitsPastDecimal: integer) : string;

var

LocaleBuffer : PChar;

CallResult : integer;

fmt : NUMBERFMT;

pfmt : ^NUMBERFMT;

begin

{ Capture number of bytes needed for result }

CallResult := GetNumberFormat(LocaleID,0,PChar(Value),nil,nil,0);

{ Allocate buffer using returned number of bytes }

LocaleBuffer := StrAlloc(CallResult + 1);

{ Format string using currency format for specified Locale }

// here - Do you know how we can get something other than the default digits
for a LocaleID?

// CallResult
:=GetNumberFormat(LocaleID,0,PChar(Value),nil,LocaleBuffer,CallResult);

fmt.NumDigits := NumDigitsPastDecimal;

pfmt := @fmt;

CallResult :=
GetNumberFormat(LocaleID,0,PChar(Value),pNumberFmtA(pfmt),LocaleBuffer,CallResult);
//This results in an error saying that the parameter is incorrect.

{ Test result to determine number of bytes written to buffer }

if CallResult = 0 then

result := SysErrorMessage(GetLastError)

else

result := LocaleBuffer;

{ De-allocate buffer }

StrDispose(LocaleBuffer);

pfmt := nil;

end;


Thanks!

Janice

Replies:

www.cryer.info
Managed Newsgroup Archive