我觉得 GetMem 和 GetMemory 的功能是一样的, 有点类似与 Format 和 FmtStr 的关系;
它们的区别只在于参数位置和返回值的区别, 看看 GetMemory 函数的源码就知道, 它其实就是调用的 GetMem.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var p: PInteger; begin GetMem(p, SizeOf(Integer)); p^ := 100; ShowMessage(IntToStr(p^)); {100} FreeMem(p); end; procedure TForm1.Button2Click(Sender: TObject); var p: PInteger; begin p := GetMemory(SizeOf(Integer)); p^ := 100; ShowMessage(IntToStr(p^)); {100} FreeMemory(p); end; end.