扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
图1 主界面 |
图2 设计完成的数据库 |
procedure TForm1.FormCreate(Sender: TObject); var mem:TMemoryStream; begin if Table1.Eof and Table1.Bof then begin with Table1 do begin Insert; FieldByName(’Name’).AsString:=’鸟’; mem:=TMemoryStream.Create(); mem.LoadFromFile(’鸟.bmp’); TBlobField(FieldByName(’Data’)).LoadFromStream(mem); Post; end; end; end; |
with Table1 do begin First; while not Eof do begin ListBox1.Items.Add(FieldByName(’Name’).AsString); Next; end; end; |
procedure TForm1.ListBox1Click(Sender: TObject); var mem:TStream; bmp:TBitmap; begin with Table1 do begin First; while not Eof do begin if FieldByName(’Name’).AsString=ListBox1.Items[ListBox1.ItemIndex] then break; Next; end; bmp:=TBitmap.Create; mem:=CreateBlobStream(FieldByName(’Data’),bmRead); mem.Position:=0; bmp.LoadFromStream(mem); self.Image1.Picture.Assign(bmp); bmp.Free; mem.Free; end; end; |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, DBTables,mmsystem, ExtCtrls; type TForm1 = class(TForm) ListBox1: TListBox; Table1: TTable; Image1: TImage; procedure FormCreate(Sender: TObject); procedure ListBox1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var mem:TMemoryStream; begin if Table1.Eof and Table1.Bof then begin with Table1 do begin Insert; FieldByName(’Name’).AsString:=’鸟’; mem:=TMemoryStream.Create(); mem.LoadFromFile(’鸟.bmp’); TBlobField(FieldByName(’Data’)).LoadFromStream(mem); Post; Insert; FieldByName(’Name’).AsString:=’样品’; mem:=TMemoryStream.Create(); mem.LoadFromFile(’样品.bmp’); TBlobField(FieldByName(’Data’)).LoadFromStream(mem); Post; Insert; FieldByName(’Name’).AsString:=’叶子’; mem:=TMemoryStream.Create(); mem.LoadFromFile(’叶子.bmp’); TBlobField(FieldByName(’Data’)).LoadFromStream(mem); Post; Insert; FieldByName(’Name’).AsString:=’荷花’; mem:=TMemoryStream.Create(); mem.LoadFromFile(’荷花.bmp’); TBlobField(FieldByName(’Data’)).LoadFromStream(mem); Post; mem.Free; end; end; with Table1 do begin First; while not Eof do begin ListBox1.Items.Add(FieldByName(’Name’).AsString); Next; end; end; end; procedure TForm1.ListBox1Click(Sender: TObject); var mem:TStream; bmp:TBitmap; begin with Table1 do begin First; while not Eof do begin if FieldByName(’Name’).AsString=ListBox1.Items[ListBox1.ItemIndex] then break; Next; end; bmp:=TBitmap.Create; mem:=CreateBlobStream(FieldByName(’Data’),bmRead); mem.Position:=0; bmp.LoadFromStream(mem); self.Image1.Picture.Assign(bmp); bmp.Free; mem.Free; end; end; end. |
图3 程序运行的初始画面 图4 程序运行结果 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者