为什么要这样转呢?直接定义str:TString100
然后lst.add(pointer(@str));不好吗

解决方案 »

  1.   

    str:TString100;
    lst.add(pointer(@((str)));
      

  2.   

    Lst.Add(Pointer(@((Str)));
    就可以了!
      

  3.   

    为什么不用TStringList来干这些事呢
      

  4.   

    我的lst里面的内容是要调用TStreamFile.write写入文件的.因为是调用得我自己派生的类,不支持string和类实例等变量,所以要转化成TString100.
    各位应该很清楚Sizeof(String)和sizeof(TString100)的区别有多大吧?而且我的str是从TStringList取出来的。
      

  5.   

    各位告诉我lst.add(pointer(@(TString100(str))));//说没有变量?此处为什么编译不通过就行了。str:TString100;
    lst.add(pointer(@((str)));lst.add(pointer(@(str[1])));这些用法都不符合我的要求
      

  6.   

    改为:
    lst.add(pointer((TString100(str))));
    试试
      

  7.   

    TString100(str)//这是错误的,父类不匹配
    将str:string;改为str:string[100]问题解决。
      

  8.   

    8请大家去 http://www.new7wonders.com/c/voting.php 投长城一票
      

  9.   

    type TString100=string[100];var lst:TList;
        str:String;
        temp:TString100;
    begin
        str:='fdfldk';
        lst:=TList.Create;
        temp:=TString100(str);
        lst.add(pointer(@temp));
    end;应该能满足你的要求。
      

  10.   

    这是帮助里的一个Example对你有帮助
    This example creates a list object and inserts two records into it. The value of the record fields are written on a paintbox:procedure TForm1.FormButton1Click(Sender: TObject);type
      PMyList = ^AList;
      AList = record
        I: Integer;
        C: Char;
      end;var  MyList: TList;
      ARecord: PMyList;
      B: Byte;
      Y: Word;
    begin
      MyList := TList.Create;
      try
        New(ARecord);
        ARecord^.I := 100;
        ARecord^.C := 'Z';
        MyList.Add(ARecord); {Add integer 100 and character Z to list}
        New(ARecord);
        ARecord^.I := 200;
        ARecord^.C := 'X';
        MyList.Add(ARecord); {Add integer 200 and character X to list}    { Now paint the items onto the paintbox}
        Y := 10;             {Variable used in TextOut function}    for B := 0 to (MyList.Count - 1) do
        begin
          ARecord := MyList.Items[B];
          Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I}
          Y := Y + 30;  {Increment Y Value again}
          Canvas.TextOut(10, Y, ARecord^.C);  {Display C}
          Y := Y + 30;  {Increment Y Value}
        end;    { Cleanup: must free the list items as well as the list }
       for B := 0 to (MyList.Count - 1) do
       begin     ARecord := MyList.Items[B];
         Dispose(ARecord);
       end;
      finally
        MyList.Free;
      end;
    end;
      

  11.   

    基本同意:drrizzt
    但要注意添加给TList的指针的有效范围问题。
    procedure TSerializedData.SaveLanguage;
    var recordStream:TRecordFile;
        fileName:string;
        i,size:integer;
        lst:TList;
        tempAry:array of TString100;
    begin
       fileName:=strDataDir+'\'+CStrLanguageFile;   size:=sizeof(TString100);
       try
          recordStream:=TRecordFile.Create(fileName,fmCreate,size);
          lst:=TList.Create;
          setLength(tempAry,strsLanguage.Count);      for i:=0 to strsLanguage.Count-1 do
          begin
             tempAry[i]:=TString100(strsLanguage[i]);
             lst.Add(pointer(@tempAry[i]));
          end;      recordStream.WriteRecords(lst);
       finally
          recordStream.Free;
          lst.Free;
       end;end;