各位大侠, 我想在程序启动时,读取上次运行时保存的bmp图像的路径,再显示出来。但总是
出现异常。 连 IDE 也崩溃了。  代码如下,不知哪里错了。 谢谢!
var
  Form1: TForm1;
  astr:Tstringlist;
  picname:string;procedure TForm1.FormCreate(Sender: TObject);
begin
   astr:=Tstringlist.Create;
  if  not FileExists(extractFilePath(application.exeName)+ 'pic.txt')  then exit;
  astr.LoadFromFile('pic.txt');  panel1.Caption:=  astr.Text;  picname:= astr.Text;  try
   image1.Picture.LoadFromFile(astr.Text);    finally
     showmessage(astr.Text);
   end;end;运行到
   image1.Picture.LoadFromFile(astr.Text);  就错。 EInvalidgraphformat   晕

解决方案 »

  1.   

    代码不是一般的烂
    小伙子好好加油!
    错误列表:
    1. extractFilePath(application.exeName)+ 'pic.txt')  不对
        extractFilePath(ParamStr(0))+ 'pic.txt'  才对2. image1.Picture.LoadFromFile(astr.Text);  
        哥, astr是一个文本list, 有可能不止一行吧?
       image1.Picture.LoadFromFile一次是不是只能导入一副图片, 你这样写要哪样?
       image1.Picture.LoadFromFile(astr[0]);  这样是导入第一副图片
      

  2.   

    你的代码中,有两个主要错误
    1、指明全路径文件名错误:
          extractFilePath(application.exeName)+ 'pic.txt'   缺少“\”
    改为:extractFilePath(application.exeName)+ '\pic.txt'2、文件名存放在pic.txt文件中,读入aStr后,aStr.text含有非路径字符
    应该这样,读取首行文件名:picname:= aStr.Strings[0];修改代码如下,试试:procedure TForm1.FormCreate(Sender: TObject);
    var aStr:TStringList;
        FileName:string;
    begin
      aStr:=TStringlist.Create;
      FileName:=extractFilePath(application.exeName)+ '\pic.txt';
      if not FileExists(FileName) then exit;
      aStr.LoadFromFile(FileName);
      panel1.Caption:=  astr.Text;
      picname:= aStr.Strings[0];
      try
        image1.Picture.LoadFromFile(picname);
      finally
        showmessage(aStr.Text);
     end;
    end;
      

  3.   

    报谦刚才回帖有错。改下如下:
    1、指明全路径文件名  ExtractFilePath(application.exeName)+ 'pic.txt'  对的
                         2、在文件名存放在pic.txt文件中,读入aStr后,aStr.text含有非路径字符,你的错就是将pic.txt当成文件名了。
    pic.txt文件中,可以保存很多文件名,一行可以保存一个文件名。   读取首行文件名:picname:= aStr.Strings[0];修改代码如下,试试:procedure TForm1.FormCreate(Sender: TObject);
    var aStr:TStringList;
        FileName:string;
    begin
      aStr:=TStringlist.Create;
      FileName:=extractFilePath(application.exeName)+ 'pic.txt';
      if not FileExists(FileName) then exit;
      aStr.LoadFromFile(FileName);
      panel1.Caption:=  astr.Text;
      picname:= aStr.Strings[0];
      try
        image1.Picture.LoadFromFile(picname);
      finally
        showmessage(aStr.Text);
     end;
    end;