各位大侠, 我想在程序启动时,读取上次运行时保存的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 晕
出现异常。 连 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 晕
解决方案 »
- cxgrid怎么判断分组栏?
- 请问:fastreport如何做横向循环报表
- DBGridEh怎样设置属性才能下拉Grid?
- delphi控件的小问题
- 关于ADO更新自带*.db数据库问题
- 在webbrowser如何复制
- 网页源文件里面用了iframe,但是iframe里面嵌套的页的代码没有包含在webbrowser的document里面,如何获取?iframe的嵌套也是用xml写出来的,
- 我的数据库内存占用怎么这么厉害!
- jackie168(玉面書生) 先进来拿分!⑤
- delphi怎么没有显示过程和函数的下拉框,查找函数好麻烦,pb和vb都有啊,
- delphi数据库连接多次会报错
- XE8下通過VerifyVersionInfo獲取win10系統版本號提示錯誤
小伙子好好加油!
错误列表:
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]); 这样是导入第一副图片
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;
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;