unit Client_Runtime_Unit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ScktComp, StdCtrls, ExtCtrls, Label3D, Gauges, Psock, NMFtp,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP;

type
  TMain = class(TForm)
    Image1: TImage;
    P_Progress: TGauge;
    Label3D1: TLabel3D;
    Label3D2: TLabel3D;
    Label3D3: TLabel3D;
    P_FileByte: TLabel3D;
    P_Address: TPanel;
    P_FileName: TPanel;
    BT_Cancel: TButton;
    Save: TSaveDialog;
    T_Thread: TTimer;
    Connect: TIdFTP;
    procedure FormCreate(Sender: TObject);
    procedure T_ThreadTimer(Sender: TObject);
    procedure SaveClose(Sender: TObject);
    procedure BT_CancelClick(Sender: TObject);
    procedure ConnectSuccess(Trans_Type: TCmdType);
    procedure ConnectWork(Sender: TObject; AWorkMode: TWorkMode;
      const AWorkCount: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


Const
  ADDRESS             = '192.164.0.13';
  PORT                = 9876;

  AC_CONNECTING       = 1;
  
Var
  Main : TMain;
  ActiveAction : Byte;
  Initialized, Connected, Errored, Transport : Boolean;
  TargetFileName, TargetAddress : String;
  FileMaxSize : Integer;
  FileName : FileName;

implementation

{$R *.DFM}

procedure TMain.FormCreate(Sender: TObject);
begin

 TargetFileName     := 'test.dat';
 TargetAddress      := '192.164.0.14';

 Initialized        := False;
 Connected          := False;
 Errored            := False;
 Transport          := False;

 If Not Save.Execute Then
 Begin
//   Connect.Cancel;
   Main.Close;
   Halt;
 End;

end;

procedure TMain.T_ThreadTimer(Sender: TObject);
begin

 If (Initialized) And (Not Connected) Then
 Begin
   Initialized        := False;
   P_Address.Caption  := TargetAddress;
   P_FileName.Caption := TargetFileName;
   Connected          := True;
   Transport          := True;

   Connect.Connect;
   showmessage(inttostr(Connect.Size('test.dat')));
   Connect.Get('test.dat', 'test.dat', true);
 End;

end;

procedure TMain.SaveClose(Sender: TObject);
begin

 Initialized        := True;
 T_Thread.Enabled   := True;

end;

procedure TMain.BT_CancelClick(Sender: TObject);
begin

// Connect.Cancel;
 Main.Close;
 Halt;

end;

procedure TMain.ConnectSuccess(Trans_Type: TCmdType);
begin

 Case Trans_Type Of
   cmdUpload : Begin
//                 Connect.Cancel;
                 Main.Close;
               End;
 End;

end;

procedure TMain.ConnectWork(Sender: TObject; AWorkMode: TWorkMode;
  const AWorkCount: Integer);
begin

 If (Connected) And (Transport) Then
 Begin
//   P_Progress.Progress := (Connect.BytesRecvd * 100) Div Connect.BytesTotal;
//   P_FileByte.Caption  := Format('%d / %d Bytes', [Connect.BytesRecvd, Connect.BytesTotal]);
 End;

end;

end.
