unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  Grids, Buttons, ClipBrd, blcksock, synsock, synautil, synamisc,
  ShlepsUtils, Unit2, Unit3, Unit4;

type

  { TForm1 }

  TForm1 = class(TForm)
    CreateConnsSpeedButton: TSpeedButton;
    RefineDataSpeedButton: TSpeedButton;
    CSVOpenDialog: TOpenDialog;
    Panel1: TPanel;
    LoadCSVSpeedButton: TSpeedButton;
    CreateObjectsSpeedButton: TSpeedButton;
    PasteSpeedButton: TSpeedButton;
    StringGrid: TStringGrid;
    procedure CreateConnsSpeedButtonClick(Sender: TObject);
    procedure CreateObjectsSpeedButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure LoadCSVSpeedButtonClick(Sender: TObject);
    procedure PasteSpeedButtonClick(Sender: TObject);
    procedure RefineDataSpeedButtonClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  TCPSocket:TTCPBlockSocket;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.LoadCSVSpeedButtonClick(Sender: TObject);
Var I:Longint;
begin
  If Not CSVOpenDialog.Execute Then Exit;
  StringGrid.LoadFromCSVFile(CSVOpenDialog.FileName);
  StringGrid.InsertColRow(True,0);
  StringGrid.FixedCols:=1;
  StringGrid.AutoSizeColumn(0);
  StringGrid.InsertColRow(False,0);
  StringGrid.FixedRows:=2;
  For I:=1 To StringGrid.RowCount-1 Do
    StringGrid.Cells[0,I]:=IntToStr(I);
  For I:=1 To StringGrid.ColCount-1 Do
    StringGrid.Cells[I,0]:=IntToStr(I);
end;

procedure TForm1.CreateObjectsSpeedButtonClick(Sender: TObject);
begin
  ObjectForm.Show;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DecimalSeparator:='.';
end;

procedure TForm1.CreateConnsSpeedButtonClick(Sender: TObject);
begin
  ConnectionForm.Show;
end;

procedure TForm1.PasteSpeedButtonClick(Sender: TObject);
Var ClipBuf:TStringList;
    I,J:Longint;
    B,PB:String;
begin
  ClipBuf:=TStringList.Create;
  ClipBuf.Text:=Clipboard.AsText;
  If ClipBuf.Count>0 Then Begin
    StringGrid.RowCount:=ClipBuf.Count+1;
    For I:=0 To ClipBuf.Count-1 Do Begin
      B:=ClipBuf[I];
      J:=0;
      Repeat
        StringGrid.Cells[J,I+1]:=GetNextToken(B,PB,#9);
        B:=PB;
        Inc(J);
        If J>=StringGrid.ColCount Then StringGrid.ColCount:=J+1;
      Until PB='';
    End;
  end;
  StringGrid.InsertColRow(True,0);
  StringGrid.FixedCols:=1;
  StringGrid.AutoSizeColumn(0);
  StringGrid.InsertColRow(False,0);
  StringGrid.FixedRows:=2;
  For I:=1 To StringGrid.RowCount-1 Do
    StringGrid.Cells[0,I]:=IntToStr(I);
  For I:=1 To StringGrid.ColCount-1 Do
    StringGrid.Cells[I,0]:=IntToStr(I);
end;

procedure TForm1.RefineDataSpeedButtonClick(Sender: TObject);
begin
  RefineDataForm.Show;
end;


end.

