unit ClientMain;

interface

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

type
  TfMain = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    eName: TLabeledEdit;
    dtBirthday: TDateTimePicker;
    ePhone: TLabeledEdit;
    eAddress: TLabeledEdit;
    eWeight: TLabeledEdit;
    eHeight: TLabeledEdit;
    btnSend: TButton;
    procedure btnSendClick(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;
  WriteCnt : integer;
  PIPtr : PPeopleInfo;
  PI : TPeopleInfo;

implementation

{$R *.dfm}

procedure TfMain.btnSendClick(Sender: TObject);
begin
  hPipe := CreateFile('\\.\pipe\ThePipe', GENERIC_WRITE,
    FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
  if hPipe = INVALID_HANDLE_VALUE then
    raise Exception.Create('З''єднання не встановлено!');

  with PI do begin
    Name := eName.Text;
    Birthday := dtBirthday.Date;
    Phone := ePhone.Text;
    Address := eAddress.Text;
    Weight := StrToFloat(eWeight.Text);
    PI.Height := StrToFloat(eHeight.Text);
  end;
  PIPtr := @PI;
  WriteFile(hPipe, PIPtr, SizeOf(PI), Cardinal(WriteCnt), nil);

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

end.
