我想用Delphi作数据结构中的链表,二叉树等等,不知道怎么像C++中动态存储分配

解决方案 »

  1.   

    create
    freeconstructor create;
    destructor Destory;
      

  2.   

    pascal中有New和delect这样的函数,前一个用在指针上面的创建
      

  3.   

    有!对应的是(new和free)
    看看帮助!
      

  4.   

    new(aaaa)      Taaaa.createaaaa.free       aaaa.free
      

  5.   

    有啊, 是
    new
    dispose
      

  6.   

    将每个节点数据封成一个类
    ;调用Create完成创建;
    ;调用Free 完成释放;如果接点没用封成类 而是一个Record 那
    ;调用new 分内存
    ;调用dispose 释放;
      

  7.   

    支持“gold_future(金色未来)”的观点,再补充点:
    如果是指针的话,可以用:分配内存:AllocMem();
    释放内存: FreeMem();
      

  8.   

    我的节点是线程类,然后用一个链表类来管理线程
    type
      pthrd=^tthrd;
      tthrd=class(tthread)
      public
        constructor Create;
      private
        id:integer;
        age:integer;
        llink:pthrd;
        rlink:pthrd;
      protected
        procedure Execute; override;
      end;  tthrdlist=class
      public
        idlabel:string;
        count:integer;
        function find(id:integer):pthrd;
        procedure insert;
        procedure delete(id:integer);
        constructor create;
      private
        first:pthrd;
        last:pthrd;
      end;procedure tthrdlist.insert;
    var
      insertitem:tlistitem;
      t1:tthrd;
    begin
      t1:=tthrd.create;
      t1.id:=fm_time.thrdlist.count+1;
      t1.age:=0;
      t1.llink:=nil;
      t1.rlink:=nil;
      if first=nil then
        first:=@t1;
      t1.llink:=last;
      last:=@t1;
      count:=count+1;
      insertitem:=fm_time.lv_cells.Items.insert(-1);
      insertitem.Caption:=inttostr(t1.id);
    end;然后我在用链表去访问每个线程,我不能获得里面的属性我原来是把线程的初始化放在create里,可也一样不能访问
    如下:
    constructor tthrd.Create;
    begin
      id:=fm_time.thrdlist.count+1;
      age:=0;
      llink:=nil;
      rlink:=nil;
      FreeOnTerminate := True;
      inherited Create(False);
    end;procedure tthrdlist.insert(thrdpoint:pthrd);
    var
      insertitem:tlistitem;
    begin
      if first=nil then
        first:=thrdpoint;
      thrdpoint.llink:=last;
      last:=thrdpoint;
      count:=count+1;
      insertitem:=fm_time.lv_cells.Items.insert(-1);
      insertitem.Caption:=inttostr(thrdpoint.id);
    end;
    插入时,
    var
      t1:tthrd;
    begin
      t1:=tthrd.Create;
      fm_time.thrdlist.insert(@t1);
    end;
    只要离开了insert方法,就不能访问了,不知道是不是因为局部变量跳出局部过程就释放呢
    望高手指教
      

  9.   

    指针用New和Dispose
    对象用Create和Free方法连表请继承TList,自己写没有必要
      

  10.   

    用TList可以么?
    该怎么作?