Server-side:
function Tservermethods1.getfile (filename:string): TStream;
Var
filepath,downfile:string;
Fs:tfilestream;
Log:teventlogger;//need to add vcl.svcmgr in uses to refer to Teventlogger
Begin
filepath:= ' d:\xe\ ';
Downfile:=filepath+filename;
Log:=teventlogger.create (' mymessage ');//Create a message
Log. LogMessage (downfile);//Output a message
Result:=nil;
If not fileexists (downfile) THEN BEGIN
Log. LogMessage (' file does not exist '),//In the output of one, will produce two logs
Exit;
End
Result:=tfilestream.create (Downfile,fmopenread);
If Result<>nil Then
result.position:=0;
End
Client:
Procedure Tform4.btn1click (Sender:tobject);
Const
buffersize=10240;
Var
Con:tservermethods1client;
Fstream:tstream;
Filefs:tfilestream;
Buffer:tbytes;
Count:integer;
Begin
Con:=tservermethods1client.create (sqlconnection1.dbxconnection);
count:=0;
SetLength (Buffer, buffersize);
After downloading from the server, rename Delphidown.pdf '
Filefs:=tfilestream.create (' d:\delphidown.pdf ', fmcreate);
Try
Fstream:=con.getfile (' delphi.pdf ');//file name on the server, the server must have
Edt1. Text:=con. ReverseString (' abc ');//This is used to drop a string flip with its own example
Repeat
Count:=fstream.read (buffer[0],buffersize);//Read the stream continuously
If Count>0 Then
Read the stream, write to ' d:\delphidown.pdf '
Filefs.writebuffer (Buffer[0],count);
Until (count<buffersize);
Except
End
End
Note the place:
1. Windows to enable the logging service. Otherwise you'll see the output log.
2. Viewing days
In Computer Management, you can view the system log:
Learn the datasanp of Yong Nan blog download files while recording Windows system logs