unit ClientMainUnit;

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, Data.DB,
  Data.SqlExpr, Vcl.StdCtrls, Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids,ClientMethods, Datasnap.DBClient,
  Datasnap.DSConnect, ClientMethods1, Datasnap.Provider, Vcl.ExtCtrls;

type
  TForm2 = class(TForm)
    DBGrid1: TDBGrid;
    Button1: TButton;
    Button2: TButton;
    DSProviderConnection1: TDSProviderConnection;
    SQLConnection1: TSQLConnection;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    OpenDialog1: TOpenDialog;
    Button3: TButton;
    Image1: TImage;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
var bmp:tbitmap; twic:twicimage;
begin

bmp:=tbitmap.Create; twic:=twicimage.Create;

opendialog1.Execute;
twic.LoadFromFile(opendialog1.FileName);
bmp.Assign(twic);


clientdataset1.Insert;
clientdataset1.FieldByName('Primary_key').AsInteger:=clientdataset1.RecordCount;
clientdataset1.FieldByName('Picture').Assign(bmp);
clientdataset1.Post;
clientdataset1.ApplyUpdates(-1);

//clientdataset1.Refresh;
clientdataset1.Close;
clientdataset1.Open;


//image1.Picture.Assign(bmp);

end;

procedure TForm2.Button2Click(Sender: TObject);
begin
clientdataset1.Delete;
clientdataset1.ApplyUpdates(-1);
end;

procedure TForm2.Button3Click(Sender: TObject);
var bmp:tbitmap;

begin
  image1.Picture:=nil;

  bmp:=tbitmap.Create;
  bmp.Assign(clientdataset1.FieldByName('Picture'));
  bmp.AlphaFormat:=afDefined;
  bmp.Transparent:=true;


  image1.Picture.Assign(bmp);
  bmp.Free

end;

procedure TForm2.FormCreate(Sender: TObject);
begin
clientdataset1.Open;
end;

end.
