Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Pipes are perfect for that job. You can implement a pipe reader thread at your service side and send corresponding string data through the pipe in ProcessFile method at client side.</p> <p>A quick, simple no error checking Pipe usage example:</p> <p>PipeServer</p> <pre><code>var Form1: TForm1; t: TReadpipe; h: THandle; msg: string; const BufSize=512; implementation {$R *.dfm} procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var chandle: THandle; begin t.Terminate; chandle := CreateFile('\\.\pipe\myNamedPipe', GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, 0); CloseHandle(chandle); t.WaitFor; t.Free; CloseHandle(h); end; procedure TForm1.FormCreate(Sender: TObject); begin t := Treadpipe.Create(false); end; { TReadPipe } procedure TReadPipe.Execute; var buf: array [0 .. BufSize-1] of char; read: cardinal; begin while not Terminated do begin h := CreateNamedPipe('\\.\pipe\myNamedPipe', PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE or PIPE_READMODE_MESSAGE or PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, BufSize, BufSize, 0, nil); ConnectNamedPipe(h, nil); if Terminated then break; msg := ''; repeat FillChar(buf, BufSize, #0); ReadFile(h, buf[0], BufSize, read, nil); msg := msg + Copy(buf, 0, read); until GetLastError &lt;&gt; ERROR_MORE_DATA; if msg &lt;&gt; '' then Synchronize( procedure begin form1.Memo1.Lines.Add(msg) end); end; DisconnectNamedPipe(h); end; </code></pre> <p>PipeClient</p> <pre><code>var Form1: TForm1; i: Integer = 0; pipe: THandle; const BufSize = 512; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var buf: array [0 .. BufSize - 1] of char; written: Cardinal; str: pchar; begin pipe := CreateFile('\\.\pipe\myNamedPipe', GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, 0); if pipe = INVALID_HANDLE_VALUE then Halt; inc(i); str := pchar('someStr' + inttostr(i)); fillchar(buf, BufSize, #0); move(str[0], buf[0], Length(str) * Sizeof(char)); WriteFile(pipe, buf[0], Length(str) * Sizeof(char), written, nil); CloseHandle(pipe); end; </code></pre> <p>Also remember pipes works as FIFO.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload