unit Unit8;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db,shellapi, ADODB,unit2, DBCtrls;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Button1: TButton;
Button2: TButton;
SaveDialog1: TSaveDialog;
DBLookupComboBox1: TDBLookupComboBox;
DataSource1: TDataSource;
ADOTable1: TADOTable;
OpenDialog1: TOpenDialog;
OpenDialog2: TOpenDialog;
ADOTable1filename: TStringField;
ADOTable1doc: TBlobField;
ADOTable1id: TLargeintField;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
filename1:widestring;
filename2:widestring;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
str:Tmemorystream;
begin
if opendialog1.Execute then
begin
filename1:=ExtractFileName(OpenDialog1.FileName);
str:=Tmemorystream.Create;
str.LoadFromFile(OpenDialog1.FileName);
str.Position:=0;
adotable1.Append;
adotable1.FieldByName('filename').AsString:=filename1;
Tblobfield(adotable1.FieldByName('doc')).loadfromstream(str);
try
adotable1.Post;
finally
str.Free;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
ss:array[0..100] of char;
begin
try
filename2:='c:/ttt/'+trim(DBLookupComboBox1.Text);
Tblobfield(adotable1.FieldByName('doc')).SaveToFile(filename2);
strpcopy(ss,filename2);
finally
shellexecute(handle,'open',ss,nil,ss,SW_SHOW);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
try
adotable1.close;
adotable1.Open;
except
sleep(1);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CreateDirectory('c:/ttt',nil);
end;
end.