Application Environment: SERVER: TROBinMessage, TROIndyHTTPServer provides the service interface: IBinaryMidService = interface
['{51084085-6d27-4eda-a55d-a9ee21686894}']
Function Add (Const ANum: AnsiString; const AType: AnsiString; const AValue: Binary): Integer;
End; client: TROBinMessage, TROWinInetHTTPChannel, TRORemoteService database Tutorial: Oracle10, the image field type is BLOBBrief Introduction: The client reads the image into the stream and transmits it to the server through the IBinaryMidService service. Then, the server stores the image in the database. 1: the client generates a stream and transmits the image to the server.
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);
10 end;
2. The server receives the stream and adds it to the database.
function TBinaryMidService.Add(Const ANum: AnsiString; const AType: AnsiString; const AValue: Binary): Integer;
var
tmpSQLStr:string;
begin
tmpSQLStr:=format('insert 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.ExecSQL;
FreeAndNil(QryTDB);
end;
3. The client obtains the data and displays the Image View Code.
1 procedure showPic;
2 var
3 Data: Variant;
4 VBinaryMidService: IBinaryMidService;
5 PicFile: TGraphic;
6 begin
7 // get the value of the data
8 VBinaryMidService: = TBinaryMidService_Proxy.Create (ROMessage, ROChannel );
9 VBinaryMidService. GetPic ('20140901', Data );
10 ClientDataSet. Data: = Data;
11 // display the image
12 if not ClientDataSet1.FieldByName ('pic '). IsNull then
13 begin
14 if ClientDataSet1.FieldByName ('pictype'). AsString = 'bmp 'then
15 // display the bmp file
16 PicFile: = TBitmap. Create;
17 else
18 if ClientDataSet1.FieldByName ('pictype'). AsString = 'jpg 'then
19 begin
20 // display JPG files
21 PicFile: = tsf-image. Create;
22 end else
23 if ClientDataSet1.FieldByName ('pictype'). AsString = 'ico 'then
24 begin
25 // display the ICO File
26 // IcoFile: = TIcon. Create; // IcoFile. Free;
27 PicFile: = TIcon. Create;
28 end else
29 if ClientDataSet1.FieldByName ('pictype'). AsString = 'png 'then
30 begin
31 // display PNG files
32 PicFile: = TPNGObject. Create;
33 end else
34 if ClientDataSet1.FieldByName ('pictype'). AsString = 'gif' then
35 begin
36 // display PNG files
37 PicFile: = TGIFImage. Create;
38 end;
39 mStream: = TMemoryStream. Create;
40 TBlobField (ClientDataSet1.FieldByName ('pic '). SaveToStream (mStream );
41 mStream. Position: = 0;
42 PicFile. LoadFromStream (MStream );
43
44 image1.Picture. Assign (PicFile );
45 PicFile. Free;
46 mStream. Free;
47 end;
48 end;
Note: To download the gifimage. pas and pngimage plug-ins (if fastReport4 is installed on the machine and the frxpngimage unit is referenced), the Image control can support PNG and GIF