我想在com件中建立一个对象集合,在集合中,使用TStringList作为子对象存储的列表。问题是在创建子对象时没有问题,在做查询时,能够查询到对象存在,在将对象返回时就出错了!使用TStringList中的Ojbect保存子对象。
  请高手指点,怎样做?

解决方案 »

  1.   

    添加
    function ThwAuditCollection.NewAudit: IhwAuditItem;
    begin
      Inc(FMaxID);
      Result := ThwAuditItem.Create;
      FList.AddObject(inttostr(FMaxID),ThwAuditItem(Result));
    end;查找
    function ThwAuditCollection.IndentOfAudit(
      AIndentID: Integer): IhwAuditItem;
    var
      Index : Integer;
    begin
      Result := nil;
      Index := FList.Indexof(inttostr(AIndentID));
      if Index < 0 then
        Result := nil
      else 
        Result := ThwAuditItem(FList.Objects[Index]);
    end;前提下FList为TStringList;已经创建。其中
    ThwAuditItem= class(TautoObject,ihwAuditItem);
      

  2.   

    什么意思?不会是叫我返回FList对象,如果是这样,那还称之为集合吗?
      

  3.   

    再加一层pointer转换就可以了:
    ThwAuditItem(Pointer(FList.Objects[Index]));