unit ServerMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls;

type
  TfMain = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    eName: TLabeledEdit;
    dtBirthday: TDateTimePicker;
    ePhone: TLabeledEdit;
    eAddress: TLabeledEdit;
    eWeight: TLabeledEdit;
    eHeight: TLabeledEdit;
    btnGo: TButton;
    procedure btnGoClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  PPeopleInfo = ^TPeopleInfo;
  TPeopleInfo = record
    Name : string[100];
    Birthday : TDate;
    Weight : real;
    Height : real;
    Phone : string[50];
    Address : string[200];
  end;

var
  fMain: TfMain;

  hPipe : THandle;
  ReadCnt : integer;
  PIPtr : PPeopleInfo;
  PI : TPeopleInfo;
  BufSize : integer;

implementation

{$R *.dfm}

procedure TfMain.btnGoClick(Sender: TObject);
begin
  BufSize := SizeOf(PI);

  hPipe := CreateNamedPipe('\\.\pipe\ThePipe', PIPE_ACCESS_INBOUND,
    PIPE_WAIT or PIPE_TYPE_BYTE, 1, BufSize, BufSize, 100, nil);
  if hPipe = INVALID_HANDLE_VALUE then
    raise Exception.Create('Канал не створено!');

  if not ConnectNamedPipe(hPipe, nil) then begin
    CloseHandle(hPipe);
    raise Exception.Create('Канал не відкрито!');
  end;

  PIPtr := @PI;
  ReadFile(hPipe, PIPtr, SizeOf(PI), Cardinal(ReadCnt), nil);
  eName.Text := PI.Name;
  dtBirthday.Date := PI.Birthday;
  ePhone.Text := PI.Phone;
  eAddress.Text := PI.Address;
  eWeight.Text := FormatFloat('0.0##', PI.Weight);
  eHeight.Text := FormatFloat('0.0##', PI.Height);

  FlushFileBuffers(hPipe);
  DisconnectNamedPipe(hPipe);
  CloseHandle(hPipe);
end;

end.
