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);
    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;
  ReadCnt : integer;
  PIPtr : PPeopleInfo;
  PI : TPeopleInfo;
  BufSize : integer;

implementation

{$R *.dfm}

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

  hMail := CreateMailSlot('\\.\mailslot\MyMailSlot', 0, MAILSLOT_WAIT_FOREVER, nil);
  if hMail = INVALID_HANDLE_VALUE then
    raise Exception.Create('Поштову скриньку не створено!');

  ReadFile(hMail, 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);

  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.
