本實例演示如何在數據庫中存取圖像文件
向窗體上添加一個TListBox組件
圖
本系統中需要設計一個新的基於Paradox
圖
為了方便測試程序
設置TTable組件的TableName屬性為Image
在程序運行初期
procedure TForm
var
mem:TMemoryStream;
begin
if Table
begin
with Table
begin
Insert;
FieldByName(
mem:=TMemoryStream
mem
TBlobField(FieldByName(
Post;
end;
end;
end;
然後按照相同的方式順序向Image
最後通過下面的代碼把Image
with Table
begin
First;
while not Eof do
begin
ListBox
Next;
end;
end;
在程序運行過程中
procedure TForm
var
mem:TStream;
bmp:TBitmap;
begin
with Table
begin
First;
while not Eof do
begin
if FieldByName(
break;
Next;
end;
bmp:=TBitmap
mem:=CreateBlobStream(FieldByName(
mem
bmp
self
bmp
mem
end;
end;
程序代碼如下
unit Unit
interface
uses
Windows
Dialogs
type
TForm
ListBox
Table
Image
procedure FormCreate(Sender: TObject);
procedure ListBox
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form
implementation
{$R *
procedure TForm
var
mem:TMemoryStream;
begin
if Table
begin
with Table
begin
Insert;
FieldByName(
mem:=TMemoryStream
mem
TBlobField(FieldByName(
Post;
Insert;
FieldByName(
mem:=TMemoryStream
mem
TBlobField(FieldByName(
Post;
Insert;
FieldByName(
mem:=TMemoryStream
mem
TBlobField(FieldByName(
Post;
Insert;
FieldByName(
mem:=TMemoryStream
mem
TBlobField(FieldByName(
Post;
mem
end;
end;
with Table
begin
First;
while not Eof do
begin
ListBox
Next;
end;
end;
end;
procedure TForm
var
mem:TStream;
bmp:TBitmap;
begin
with Table
begin
First;
while not Eof do
begin
if FieldByName(
break;
Next;
end;
bmp:=TBitmap
mem:=CreateBlobStream(FieldByName(
mem
bmp
self
bmp
mem
end;
end;
end
保存文件
在TListBox組件中選中一項後
圖
圖
From:http://tw.wingwit.com/Article/program/Delphi/201311/8527.html