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. |