问题来源: http://www.cnblogs.com/del/archive/2008/05/02/1179416.html#1179645

我觉得 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.

相关文章:

  • 2022-12-23
  • 2021-12-01
  • 2021-11-26
  • 2021-12-09
  • 2021-08-16
  • 2021-08-16
猜你喜欢
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
相关资源
相似解决方案