{ DISQLite3 incremental blob demo. Using the incremental blob API, DISQLite3
  can conveniently handle large blobs with no strains to memory.

  Visit the DISQLite3 Internet site for latest information and updates:

    http://www.yunqa.de

  Copyright (c) 2006-2021 Ralf Junker, Yunqa <delphi@yunqa.de>

------------------------------------------------------------------------------ }

unit DISQLite3_Incremental_Blob_fEdit;

{$I DICompilers.inc}
{$I DISQLite3.inc}

interface

uses
  {$IFDEF HAS_UNITSCOPE}
  System.Classes, Vcl.Controls, Vcl.Forms, Vcl.StdCtrls
  {$ELSE HAS_UNITSCOPE}
  Classes, Controls, Forms, StdCtrls
  {$ENDIF HAS_UNITSCOPE};

type
  TfrmIncrementalBlobEdit = class(TForm)
    edtName: TEdit;
    edtComment: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    btnCancel: TButton;
    btnOK: TButton;
    gbxBlobContents: TGroupBox;
    rbBlobNoChange: TRadioButton;
    rbBlobDelete: TRadioButton;
    rbBlobReplace: TRadioButton;
    edtBlobFileName: TEdit;
    btnSelectFile: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btnSelectFileClick(Sender: TObject);
    procedure BlobChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmIncrementalBlobEdit: TfrmIncrementalBlobEdit;

implementation

uses
  {$IFDEF HAS_UNITSCOPE}
  System.SysUtils, Vcl.Dialogs,
  {$ELSE HAS_UNITSCOPE}
  SysUtils, Dialogs,
  {$ENDIF HAS_UNITSCOPE}
  DISQLite3_Incremental_Blob_fMain;

{$R *.dfm}

procedure TfrmIncrementalBlobEdit.FormCreate(Sender: TObject);
begin
  Caption := APP_TITLE + ' - Edit';
end;

//------------------------------------------------------------------------------

procedure TfrmIncrementalBlobEdit.btnSelectFileClick(Sender: TObject);
var
  OpenDlg: TOpenDialog;
begin
  OpenDlg := TOpenDialog.Create(nil);
  try
    OpenDlg.FileName := edtBlobFileName.Text;
    if OpenDlg.Execute then
      begin
        edtBlobFileName.Text := OpenDlg.FileName;
        rbBlobReplace.Checked := True;
      end;
  finally
    OpenDlg.Free;
  end;
end;

//------------------------------------------------------------------------------

procedure TfrmIncrementalBlobEdit.BlobChange(Sender: TObject);
var
  FN: string;
begin
  FN := edtBlobFileName.Text;
  btnOK.Enabled :=
    rbBlobNoChange.Checked or
    rbBlobDelete.Checked or
    ((FN <> '') and FileExists(FN));
end;

end.

