unit MainClient;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, WinSock, 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 FormDestroy(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;

  PIPtr : PPeopleInfo;
  PI : TPeopleInfo;

implementation

{$R *.dfm}

procedure TfMain.btnSendClick(Sender: TObject);
var S : TSocket;
    Addr : TSockAddr;
    Data : TWSAData;
begin
  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;

  WSAStartup($101, Data);
  S := Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  Addr.sin_family := AF_INET;
  Addr.sin_port := htons(2212);
  Addr.sin_addr.S_addr := inet_addr('127.0.0.1');
  //FillChar(Addr.sin_zero, SizeOf(Addr.sin_zero), 0);
  if connect(S, Addr, SizeOf(TSockAddr)) <> 0 then begin
    MessageDlg('З''єднання не встановлено!', mtError, [mbCancel], 0);
  end else
    send(S, PIPtr^, SizeOf(PI), 0);

  closesocket(S);
end;

procedure TfMain.FormDestroy(Sender: TObject);
begin
  WSACleanup;
end;

end.
