在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
马上能想到的函数有: GetMem AllocMem ReallocMem FreeMem GetMemory ReallocMemory FreeMemory New Dispose NewStr DisposeStr StrNew StrAlloc StrDispose GlobalAllocPtr GlobalFreePtr WideStrAlloc AnsiStrAlloc StrDispose Move MoveMemory CopyMemory ZeroMemory FillMemory FillChar StrBufSize
var p: PChar; begin p := StrAlloc(256); GetWindowText(Handle, p, StrBufSize(p)); ShowMessage(p); {Form1} StrDispose(p); end;
//获取 WINDOWS 所在目录 var buf: array[0..MAX_PATH] of Char; begin GetWindowsDirectory(buf, Length(buf)); ShowMessage(buf); {C:\WINDOWS} end;
var p: PChar; begin p := '万一的 Delphi 博客'; ShowMessage(p); {万一的 Delphi 博客} end;
//获取系统目录 var p: PChar; begin p := PChar(StringOfChar(Char(0), 256)); {反复一个空字符 256 次成一个字符串, 然后转为 PChar} GetSystemDirectory(p, StrBufSize(p)); ShowMessage(p); {C:\WINDOWS\system32} end;
//设置窗口标题 var p: PChar; begin p := '窗口新标题'; SetWindowText(Handle, p); end; //也可以直接给常量 begin MessageBox(Handle, '提示信息', '标题', MB_OK); end; //如果是给字符串的变量或常量, 则需要转换一下 var str: string; begin str := '万一的 Delphi 博客'; TextOut(Canvas.Handle, 10, 10, PChar(str), Length(str)); {在窗体上输出文字, 此代码不能在 OnCreate 事件中} end;
var p1,p2: PChar; begin p1 := 'Delphi'; p2 := StrNew(p1); ShowMessageFmt('%s, %s', [p1, p2]); {Delphi, Delphi} p1 := '2009'; ShowMessageFmt('%s, %s', [p1, p2]); {2009, Delphi} StrDispose(p2); {释放自己申请的} end;
var p1,p2: PChar; begin p1 := 'Delphi'; p2 := p1; ShowMessageFmt('%s, %s', [p1, p2]); {Delphi, Delphi} p1 := '2009'; ShowMessageFmt('%s, %s', [p1, p2]); {2009, Delphi} end;
http://www.cnblogs.com/del/archive/2008/11/08/1329543.html |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论