标签:
wvsprintf( Output: PChar; {用于返回的缓冲区} Format: PChar; {格式; 类似与 Format 的格式, 应该是和 C 语言的 printf 的格式相同} arglist: va_list {数组指针} ): Integer; {返回到缓冲区的实际字符串的长度}
//例一: var buf: PChar; arr: array[0..1] of Pointer; begin buf := PChar(StringOfChar(#0, 255)); {我这样准备缓冲区} arr[0] := PChar(‘万一‘); arr[1] := Pointer(123); wvsprintf(buf, ‘%s, %d‘, @arr); ShowMessage(buf); {显示结果: 万一, 123} end; //例二: var buf: PChar; arr: array of Pointer; {和上一例的区别是这里用了动态数组} begin buf := PChar(StringOfChar(#0, 255)); SetLength(arr, Length(arr)+1); arr[High(arr)] := PChar(‘万一‘); SetLength(arr, Length(arr)+1); arr[High(arr)] := Pointer(123); wvsprintf(buf, ‘%s, %d‘, PChar(arr)); //wvsprintf(buf, ‘%s, %d‘, @arr[0]); {或者这样} ShowMessage(buf); {显示结果: 万一, 123} end;
wsprintf( Output: PChar; {用于返回的缓冲区} Format: PChar; {格式} Data: Pointer {数据指针} ): Integer; {返回到缓冲区的实际字符串的长度}
... implementation {$R *.dfm} function wsprintf(Output: PChar; Format: PChar; Data: Pointer): Integer; stdcall; external user32 name ‘wsprintfA‘; ...如果全局使用需要这样声明:
... function wsprintf(Output: PChar; Format: PChar; Data: Pointer): Integer; stdcall; var Form1: TForm1; implementation {$R *.dfm} function wsprintf; external user32 name ‘wsprintfA‘; ...
function wsprintf(Output: PChar; Format: PChar; Data: Pointer): Integer; stdcall; external user32 name ‘wsprintfA‘; procedure TForm1.FormCreate(Sender: TObject); var buf: PChar; begin buf := PChar(StringOfChar(#0, 255)); wsprintf(buf, ‘我是%s‘, PChar(‘万一‘)); ShowMessage(buf); {我是万一} wsprintf(buf, ‘现在是 %d 年‘, Pointer(2008)); ShowMessage(buf); {现在是 2008 年} end;
var buf: PChar; arr: array[0..0] of Pointer; i: Integer; begin buf := PChar(StringOfChar(#0, 255)); i := MaxInt; arr[0] := Pointer(i); ShowMessage(Format(‘%x‘, [i])); {7FFFFFFF} ShowMessageFmt(‘%x‘, [i]); {7FFFFFFF} wvsprintf(buf, ‘%x‘, @arr); ShowMessage(buf); {7fffffff} end;
WinAPI: wvsprintf 与 wsprintf - Windows 的格式化输出函数(转)
标签:
原文地址:http://www.cnblogs.com/moonwind/p/4450367.html