unit ClientUnit_9_1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DBXDataSnap, IPPeerClient, Data.DBXCommon, Vcl.DBCtrls,
  Data.DB, Datasnap.DBClient, Datasnap.DSConnect, Data.SqlExpr, Vcl.StdCtrls, Vcl.Grids, Vcl.DBGrids,
  ClientMethods_9_1,Contnrs;

type
  TForm3 = class(TForm)
    DBGrid1: TDBGrid;
    bUpload_by_Parts: TButton;
    SQLConnection1: TSQLConnection;
    DSProviderConnection1: TDSProviderConnection;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    DBImage1: TDBImage;
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    procedure bUpload_by_PartsClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}


procedure NTransfer(ms:tmemorystream;packetsize:int64);
var smc:TServerMethods1Client;
    N:integer;
    i:integer;
    bufferstream:tmemorystream;
    Buffer:TBytes;
    Objectlist:TObjectlist;
begin
    //Создание
    Objectlist:=tobjectlist.Create;
    bufferstream:=tmemorystream.Create;


    ms.Position:=0;

    N:=(ms.Size div packetsize);  N:=2;
     if N=0 then exit; // Для "Маленьких" файлов меньше packetsize...

 //Заполнение Objectlist...

{
 for i := 1 to N do
  begin
   smc:=TServerMethods1Client.Create(Form3.sqlconnection1.DBXConnection);
   ObjectList.Add(smc);
  end;
}

  showmessage(inttostr(ms.Size));

    for I := 1 to N do
      begin
         bufferstream.Clear;
         buffer:=nil;

 {         ms.ReadBuffer(buffer,packetsize); // Прочитали в буфер из потока...


          bufferstream.WriteBuffer(buffer,packetsize); //Записали в другой поток
          bufferstream.Position:=0;

          ms.Position:=packetsize*i; // Передвинули позицию
}
    //     (Objectlist[i] as TServerMethods1Client).GetstreamByPackets(bufferstream,packetsize);
      end;




    //Удаление
    Objectlist.Free;
    bufferstream.Free;

end;



procedure TForm3.bUpload_by_PartsClick(Sender: TObject);
var bmp:tbitmap;
    twic:twicimage;
    ms:tmemorystream;
 //   const const_packetsize=51200;

begin
  //Создание...
   bmp:=tbitmap.Create;
   twic:=twicimage.Create;
   ms:=tmemorystream.Create;

   //Загрузка картинки в память...
   opendialog1.Execute;
   twic.LoadFromFile(opendialog1.FileName);
   bmp.Assign(twic);
   bmp.SaveToStream(ms);


   Ntransfer(ms,51200);


   //Удаление
   bmp.Free;
   twic.Free;
   ms.Free;

end;

procedure TForm3.Button1Click(Sender: TObject);
var smc:tservermethods1client;
begin
  smc:=tservermethods1client.Create(sqlconnection1.DBXConnection);

  clientdataset1.Delete;
  clientdataset1.ApplyUpdates(-1);
  smc.ApplyUpdates;

  smc.Free;

end;

procedure TForm3.FormCreate(Sender: TObject);
begin
sqlconnection1.Connected:=true;
clientdataset1.Active:=true;
end;

end.
