X
xsgdhjt
Unregistered / Unconfirmed
GUEST, unregistred user!
帮我查查错误,我把一个文件夹下的图片文件,有BMP与JPG两类文件,只把BMP文件导入数据库,导入后删除BMP文件,老是弹出错误框,“Projeect prjsavetoall.exe raised exception class EInvalidGraphic with message 'Bitmap image is not valid',process stopped,use step or run Contiune ”代码如下:
{
unit savetoall;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Edit1: TEdit;
Memo1: TMemo;
ADOConnection1: TADOConnection;
Table_history_data: TADOTable;
ADOQuery1: TADOQuery;
Table_history_datafilename: TStringField;
Table_history_datapic: TBlobField;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure GetAllFileName(SourcePath:String);
end;
var
Form1: TForm1;
OriginalBmp,ThumbBmp:Tbitmap;
implementation
{$R *.dfm}
procedure TForm1.GetAllFileName(SourcePath:String);
var
Found:Integer;
sr: TSearchRec;
begin
Found:=FindFirst(SourcePath+'/*.*',faAnyFile,sr);
while Found=0 do
begin //!!!
if (sr.Name='.') or (sr.Name='..') then //如果是父目录则推出进入下次循环
begin
Found := FindNext(sr);
continue;
end
else
begin
if not(sr.Attr and faDirectory > 0) then //非子目录
begin
try
if (LowerCase(ExtractFileExt(SourcePath+'/'+sr.Name)))='.bmp' then
begin
Memo1.Lines.Add(SourcePath+'/'+sr.Name); //将文件的路径写到Memo中,你可以写到数据库中
OriginalBmp:=Tbitmap.Create;
OriginalBmp.LoadFromFile(SourcePath+'/'+sr.Name);
Table_history_data.Open;
Table_history_data.Last;
Table_history_data.Append;
Table_history_data.FieldByName('pic').Assign(OriginalBmp);
Table_history_data.FieldValues['filename']:=SourcePath+'/'+sr.Name;
end
else
ListBox1.AddItem(SourcePath+'/'+sr.Name,ListBox1);
finally
OriginalBmp.Free;
DeleteFile(SourcePath+'/'+sr.Name);
end;
end
else //是子目录
GetAllFileName(SourcePath+'/'+sr.Name);
end;
Found:= FindNext(sr);
end;
FindClose(sr);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.text:='C:/lmck/bmp';
GetAllFileName(Edit1.text);
end;
}
{
unit savetoall;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Edit1: TEdit;
Memo1: TMemo;
ADOConnection1: TADOConnection;
Table_history_data: TADOTable;
ADOQuery1: TADOQuery;
Table_history_datafilename: TStringField;
Table_history_datapic: TBlobField;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure GetAllFileName(SourcePath:String);
end;
var
Form1: TForm1;
OriginalBmp,ThumbBmp:Tbitmap;
implementation
{$R *.dfm}
procedure TForm1.GetAllFileName(SourcePath:String);
var
Found:Integer;
sr: TSearchRec;
begin
Found:=FindFirst(SourcePath+'/*.*',faAnyFile,sr);
while Found=0 do
begin //!!!
if (sr.Name='.') or (sr.Name='..') then //如果是父目录则推出进入下次循环
begin
Found := FindNext(sr);
continue;
end
else
begin
if not(sr.Attr and faDirectory > 0) then //非子目录
begin
try
if (LowerCase(ExtractFileExt(SourcePath+'/'+sr.Name)))='.bmp' then
begin
Memo1.Lines.Add(SourcePath+'/'+sr.Name); //将文件的路径写到Memo中,你可以写到数据库中
OriginalBmp:=Tbitmap.Create;
OriginalBmp.LoadFromFile(SourcePath+'/'+sr.Name);
Table_history_data.Open;
Table_history_data.Last;
Table_history_data.Append;
Table_history_data.FieldByName('pic').Assign(OriginalBmp);
Table_history_data.FieldValues['filename']:=SourcePath+'/'+sr.Name;
end
else
ListBox1.AddItem(SourcePath+'/'+sr.Name,ListBox1);
finally
OriginalBmp.Free;
DeleteFile(SourcePath+'/'+sr.Name);
end;
end
else //是子目录
GetAllFileName(SourcePath+'/'+sr.Name);
end;
Found:= FindNext(sr);
end;
FindClose(sr);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.text:='C:/lmck/bmp';
GetAllFileName(Edit1.text);
end;
}