if opendialog1.Execute then
begin
Q.Text:=Opendialog1.Files.Text;
end;
以上选择文件
------------------------------
以下读取文件出错
str:=TStringList.Create;
if Length(Q.Text)>0  then
begin
filestr:=Q.Text;
str.LoadFromFile(filestr);-----------------------
出错提示:Cannot open file c:\q.txt

解决方案 »

  1.   

    补充:不用opendialog选择时,直接指定路可读取
    str:=TStringList.Create;
    if Length(Q.Text)>0  then
    begin
    filestr:=Q.Text;
    str.LoadFromFile('c:\q.txt');
    仅仅以上可以读取
      

  2.   

    if opendialog1.Execute then
    begin
        Q.Text:=Opendialog1.FileName;
    end;
      

  3.   

    同意 Q.Text:=Opendialog1.FileName;如果用 Opendialog1.Files.Text 文件名后还有回车换行变成str.LoadFromFile('q.txt' + #13#10);
      

  4.   

    谢谢 gzmhero(hihihi) 、zswang(伴水清清)(专家门诊清洁工),问题解决!
      

  5.   

    Q.Text:=Opendialog1.Files.Text;
    改为
    Q.Text:=Opendialog1.FileName;