Application Environment: Server: TROBinMessage, TROIndyHTTPServer
Provide service interfaces:
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 BLOB
Brief 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.
I. The client generates a service that has been circulated and transmitted 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 ('20140901', 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 data and displays images.
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