Do somethin ': trobinmessage,troindyhttpserver
Supply Interface:
Ibinarymidservice = interface
["" {51904085-6d27-4eda-a55d-a9ee21686894} "]
function Add (Const anum:ansistring; Const atype:ansistring; Const avalue:binary): Integer;
End
Client: Trobinmessage,trowininethttpchannel,troremoteservice
Database: Oracle10, picture field type is blob
Brief Introduction : The client reads the picture into the stream and passes it through the process Ibinarymidservice to the office, and then has the agent to deposit into the database.
One: Client generates smooth over-the-handle transfer to the office
1 procedure Savepic;
2 var
3 Tmpstream:trobinarymemorystream;
4 Vbinarymidservice:ibinarymidservice;
5 begin
6 tmpstream:=trobinarymemorystream.create;
7 vbinarymidservice:=tbinarymidservice_proxy.create (Romessage,rochannel);
8 Image1.Picture.Graphic.SaveToStream (Tmpstream);
9 Vbinarymidservice.add ("0001" ", Pictype,tmpstream);
Ten end;
Two: The service end takes over the stream grows to the database
function Tbinarymidservice.add (Const anum:ansistring; Const atype:ansistring; Const avalue:binary): Integer;
Var
tmpsqlstr:string;
Begin
Tmpsqlstr:=format ("Into test (num,atype,pic) VALUES (%s,%s,:0)", [Quotedstr (Anum), Quotedstr (Atype)]);
Dborder.addpic (Tmpsqlstr,avalue);
End
--------------Ucdborder----------------------
function Dborder.addpic (asqlstr:string; Avalue)
Var
Qrytdb:tadoquery;
Begin
qrytdb:= tadoquery.create (nil);
Qrytdb.close;
QryTDB.SQL.Clear;
Qrytdb.connection:=conn;
QRYTDB.SQL.ADD (SQLSTR);
QryTDB.Parameters.ParamByName ("1"). Loadfromstream (Avalue,ftblob);
Qrytdb.sql;
Freeandnil (QRYTDB);
End
Three: The client obtains the data and displays the picture
View Code
1 procedure Showpic;
2 var
3 data:variant;
4 Vbinarymidservice:ibinarymidservice;
5 picfile:tgraphic;
6 begin
7//Get data assigned to
8 Vbinarymidservice:=tbinarymidservice_proxy.create (Romessage,rochannel);
9 Vbinarymidservice.getpic ("00001", "Data");
Ten clientdataset.data:=data;
11//Display Picture
If not Clientdataset1.fieldbyname ("" Pic "). IsNull Then
Begin
If Clientdataset1.fieldbyname ("Pictype" "). asstring=" "BMP" Then
15//Display BMP file
Picfile:=tbitmap.create;
+ Else
If Clientdataset1.fieldbyname ("Pictype" "). asstring=" "JPG" Then
Begin
20//Display JPG file
Picfile:=tjpegimage.create;
End Else
If Clientdataset1.fieldbyname ("Pictype" "). asstring=" ICO "" Then
Begin
25//Show ICO file
//icofile:=ticon.create; Icofile.free;
Picfile:=ticon.create;
-end Else
If Clientdataset1.fieldbyname ("Pictype" "). asstring=" "PNG" Then
Begin
31//Display PNG file
Picfile:=tpngobject.create;
End Else
If Clientdataset1.fieldbyname ("Pictype" "). asstring=" GIF "" Then
Begin
36//Display PNG file
Panax Notoginseng picfile:=tgifimage.create;
The end;
Mstream:=tmemorystream.create;
Tblobfield ("Clientdataset1.fieldbyname" ("Pic")). Savetostream (Mstream);
Mstream.position: = 0;
Picfile.loadfromstream (Mstream);
43
Image1. Picture.assign (Picfile);
Picfile.free;
Mstream.free;
The end;
The end;
Storing pictures via process remobject components