每一条记录生成一个类,我怎么对这些类进行管理。使用集合么????

解决方案 »

  1.   

    看你的要求了用Tlist可以,数组也可以
      

  2.   

    TStringList;
    假设你的类:TTestClass;procedure Test(const n: Integer);
    var
      strList: TStringList;
      tClass: TTestClass;
      i: Integer;
    begin
      if (n <= 0) then exit
      else
      begin
        strList:= TStringList.Create;
        for i:= 0 to n do 
        begin
          tClass:= TTestClass.Create;
          strList.AddObject('tClass'+InttoStr(i),tClass);
        end;
      end;
      
      strList.Free;
    end;
      

  3.   

    忘了说一句:
    当然你可以写个函数返回上述的strList对象。
    当你使用上述的strList对象时,要注意释放每个TTestClass对象。
      

  4.   

    函数的实现:function GetObjList(const n : Integer): TStringList;
    var
      i: Integer;
      tClass: TTestClass;
    begin
      Result:= TStringList.Create;
      if n <= 0 then 
      begin 
        Result.Free;
        exit;
      end;
      for i := 0 to n do
      begin
        tClass:= TTestClass.Create;
        Result.AddObject('tClass'+IntToStr(i),tClass);
      end;
    end;use above function GetObjList;const n = 10;procedure TForm1.Button1Click(Sender: TObject);
    var
      strList: TStringList;
      i: Integer;
    begin
      strList:= GetObjList(n);
      for i:= 0 to strList.Count -1 do
      begin
        memo1.Lines.Add(TTestClass(strList.Objects[i]).Name);// Name 是TTestClass的一个属性
        strList.Objects[i].Free;
      end;
      strList.Free;end;
      

  5.   

    使用TObjectList对象来进行管理!!!!