我有好几种类型的Record,不同的Pointer,放在TreeView的Item的Data中,我遍历的时候得到的是Pointer,如何判断是属于不同的Record

解决方案 »

  1.   

    可以把RECORD换成CLASS,然后来区分
      

  2.   

    做个简单的扩展啊const
      DATA1 = 1;
      DATA2 = 2;
      DATA3 = 3;type
      TData = record
        DataType: Integer;
        Data: Pointer;
      end;  TData1 = record  end;  TData2 = record  end;  TData3 = record  end;
    function NewData1(AData1: TData1): TData;
    begin
      New(Result);  
      Result.DataType := Data1;
      Result.Data := AllocMem(SizeOf(TData1));
      Result.Data^ := AData1;
    end;....
      

  3.   

    你可以规划一下你的Record类型,把第一个成员设计为类型标记,如:
    type
      RecType = (type1, type2, type3); 
      PRecType = ^RecType;  Rec1 = record
        typeid: RecType;
        data1: ...;
      end;
      PRec1 = ^Rec1;  Rec2 = record
        typeid: RecType;
        data2: ...;
      end;
      PRec2 = ^Rec2;  Rec3 = record
        typeid: RecType;
        data3: ...;
      end;
      PRec3 = ^Rec3;
    使用时:
      p: Pointer;  p = treenode.Data;
      case PRecType(p)^ of
        type1: 处理第一种类型
        type2: 处理第二种类型
        type3: 处理第三种类型
      end;
      

  4.   

    楼上的不错,还有一个问题:
    Delphi中有无可以实现 add(tag:integer;object:TObject)的List,Hash过的,可以快速实现定位
      

  5.   

    INIFiles有一个,针对字符串的但如果你是在运行状态经常性的Add的话,建议你不使用,因为Add后实在是慢,最好是存储起来再使用。不然自己写一个二分法的LIST,也简单。
      

  6.   

    大家还没睡?欢迎加我 QQ 21110167,好久不用delphi,最近正好用delphi做个东西
      

  7.   

    建议把不同的record封装成不同的类,这样使用起来方便
      

  8.   

    就用TObjectList;
    把信息封装不同的类,
    Tmain = class;
    public
      ftype: integer; //用来区分不同的类型
      constructor Create(vtype: integer); virtual;
    end;Tchild = Class(Tmain)
    public
      //data: ...你的相关数据
      constructor Create(vtype: integer); override;
    end;
    end;////////
    var 
      list: TObjectList;
      a: Tmain;
    begin
      a := Tchild.create(1);
      list.add(a);
      //添加多个.... 
      for i := 0 to list.cout-1 do
      begin
        case Tmain(list.items[i]).ftype do
        1:;
        2:;
      end;
    end;
      

  9.   

    根本没有必要写成类。因为数据并不复杂,写成类的话每次使用都要实例化,用:agui(阿贵: 高级图形用户界面)的方法就可以了。
      

  10.   

    agui的方法可行。。也可以使用变体记录的方法,如果有兴趣,楼主也可以看一下typinfo.pas中的内容