请问如何获得listbox当前选中项的内容,应该是string的吧

解决方案 »

  1.   

    没错是string.
    var  F: File;
      i: Integer;
    begin
      for i := 0 to (FileListBox1.Items.Count - 1) do begin
      try
        if FileListBox1.Selected[i] then 
        begin
          if not FileExists(FileListBox1.Items.Strings[i]) then begin
            MessageDlg('File: ' + FileListBox1.Items.Strings[i] + 
                       ' not found', mtError, [mbOk], 0);
            Continue;
          end;
          AssignFile(F, FileListBox1.Items.Strings[i]);      Reset(F, 1);
          ListBox1.Items.Add(IntToStr(FileSize(F)));
          CloseFile(F);
        end;
       finally
       { do something here }
       end;
      end;
    end;
      

  2.   

    不知道是不是这个:
    var
      str:string;
    然后str:=ListBox.Items[ListBox.ItemIndex];就可以取出当前选中的项了
      

  3.   

    edit1.Text:=listbox1.Items.Text;//把Listbox中全部内容放入edit1.text中
    edit1.Text:=listbox1.Items[0];//把第0行的内容放入,其他行同理
      

  4.   

    function GetSelectString(lb: TListBox): String;
    var
      sRet: String;
      Js: Integer;
    begin
        sRet := '';    for Js := 0 to lb.Items.Count - 1 do
        begin
            if lb.Selected[Js] then
            begin
                sRet := lb.Items.Strings[Js];            break;
            end;
        end;    Result := sRet;
    end;
      

  5.   

    zhangnan623(狐和鹅)
    他说的对!