delphi 中申明应该是 procedure GetMem(var P:Pointer;Size:Integer);
我模仿着写了一个  procedure GetMemEx(var P:Pointer;Size:Integer);
原本以为一模一样。
但是,我随便写了一个指针类型
type
  PMyRecord = ^TMyRecord;
  TMyRecord = record
    X:Integer;
    Y:Double;
    Z:string[10];
  end;var pp:PMyRecord;
begin
  GetMem(pp,32);
  GetMemEx(pp,32);结果我写的函数报错: [Pascal Error] Unit1.pas(91): E2033 Types of actual and formal var parameters must be identical如果改成 GetMemEx(Pointer(pp),32); 强制转换一下就 ok为什么会这样?

解决方案 »

  1.   

    你传递的是var PMyRecord类型,不是无类型指针,需要初始化
      

  2.   

    是不是Getmem有多态
    procedure GetMem(var P:Pointer;Size:Integer);
    你是在哪看到的
      

  3.   

    初始化而用的吧>>>>>>>>>>>>>>>
      

  4.   

    GetMem(pp,sizeof(tmyrecord));  这样行不?
      

  5.   

    Getmem可以给任意的指针分配你想分配的内存大小
      

  6.   

    delphi帮助
    UnitSystemCategorydynamic allocation routinesDelphi syntax:procedure GetMem(var P: Pointer; Size: Integer);DescriptionP is a variable of any pointer type. Size is an expression specifying the size in bytes of the dynamic variable to allocate. Access the newly allocated memory by dereferencing the pointer; that is, use P^. P is a variable of any pointer type
    已经说明P是任意指针类型变量,估计做过处理了,详细就不清楚了
      

  7.   

    1 GetMem是编译器优化过的函数
    2 你那个函数是怎样实现的呢?
      

  8.   

    跟踪了下,GetMem调用的system单元的 _GetMem函数0045ADF0 B8C8000000       mov eax,$000000c8
    0045ADF5 E8C278FAFF       call @GetMem
    0045ADFA C3               ret 
    0045ADFB 90               nop 这段代码只有传入参数 $000000c8 200, 应该是编译器优化了的 
      

  9.   

    function _GetMem(Size: Integer): Pointer;你可以模仿这个原型。
      

  10.   


    我也认为 Delphi 是通过 MemManage 调用了 _GetMem 函数。
    好吧,太复杂的问题,我就不细究了。