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);
    procedure FormCreate(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;

  hMail : THandle;
  WriteCnt : integer;
  PIPtr : PPeopleInfo;
  PI : TPeopleInfo;

implementation

{$R *.dfm}

procedure TfMain.btnSendClick(Sender: TObject);
begin
  hMail := CreateFile('\\.\mailslot\MyMailSlot', GENERIC_WRITE,
    FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);
  if hMail = 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(hMail, PIPtr^, SizeOf(PI), Cardinal(WriteCnt), nil);

  FlushFileBuffers(hMail);
  CloseHandle(hMail);
end;

procedure TfMain.FormCreate(Sender: TObject);
var CN : PChar;
    CNSize : DWORD;
begin
  CNSize := 200;
  GetMem(CN, CNSize);
  if GetComputerName(CN, CNSize) then Caption := Caption + ' : ' + CN;
  FreeMem(CN);
end;

end.
