while not Eof(FtxtFile) do
    begin
      ReadLn(FtxtFile, sqlText);
      ws := sqlText;
      ReadLn(FtxtFile, sqlText);
      ws1 := sqlText;    //  ShowMessage('ws: ' + ws + '  ws1: ' + ws1);
      CheckListBox1.Items.AddObject(IntToStr(I) + '   ' + ws, TObject(pchar(ws1)));
      I := I + 1;
    end;我的本意是CheckListBox1有一个名称和一个值,但是  ShowMessage(pchar(CheckListBox1.Items.Objects[CheckListBox1.ItemIndex]));  总是出错,出来好象乱码一样的东东,请大家帮忙看看

解决方案 »

  1.   

    TObject(pchar(ws1)一个字符串(好像是)怎么能强制转换为TObject,这样的代码不出错...
      

  2.   

    如果文件中的内容包含中文等非英语字符,建议定义AnsiString类型字符串.
      

  3.   

    感觉楼上说的对.另外:CheckListBox1.Items.AddObject(IntToStr(I) + '   ' + ws, TObject(pchar(ws1)));
    感觉还应该加个'\0',即C中的字符串结尾.
      

  4.   

    TWS = class
      private
        FWS: string;
      protected
      public
        property WS: string read FWS write FWS;
      end;var
      Form1: TForm1;implementation
    {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      FtxtFile: TextFile;
      sqlText: string;
      I: Integer;
      WS: TWS;
    begin
      I:= 0;
      AssignFile(FtxtFile, 'C:\Return.Txt');
      Reset(FtxtFile);
      while not Eof(FtxtFile) do
      begin
        ReadLn(FtxtFile, sqlText);
        WS := TWS.Create;
        WS.WS := sqlText;
        CheckListBox1.Items.AddObject(IntToStr(I)+' '+WS.WS, WS);
        I := I + 1;
      end;
    end;procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
    if CheckListBox1.ItemIndex >= 0 then
    ShowMessage(TWS(CheckListBox1.Items.Objects[CheckListBox1.ItemIndex]).WS);
    end;
      

  5.   

    沒有解決問題啊﹐ 
    我的本意是CheckListBox1有一个名称和一个值﹐我點擊CheckListBox1的一個ITEM﹐要能得到它所對應的值﹐﹐謝謝
      

  6.   

    你把TWS(CheckListBox1.Items.Objects[CheckListBox1.ItemIndex]).WS写到Click事件里面就可以了
      

  7.   

    謝謝sanmaotuo(老冯)﹐我把它變成以下的
    TWS = class
      private
        FWS: string;
        FWS_url: string;
      protected
      public
        property WS: string read FWS write FWS;    
        property WS_url: string read FWS_url write FWS_url;
      end;就可以了,謝謝你
    結了