unit Unit25;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.ExtCtrls,
  Vcl.Imaging.jpeg, Vcl.Mask, DBCtrlsEh, Vcl.ExtDlgs;

type
  TfPhotoEdit = class(TForm)
    Panel1: TPanel;
    bbOk: TBitBtn;
    bbCancel: TBitBtn;
    Image1: TImage;
    Panel2: TPanel;
    DBEditEh1: TDBEditEh;
    bOpen: TButton;
    opd: TOpenPictureDialog;
    procedure bOpenClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fPhotoEdit: TfPhotoEdit;

implementation

{$R *.dfm}

uses Unit1, Unit21;

procedure TfPhotoEdit.bOpenClick(Sender: TObject);
   var
      curDir, new_fn : string;
begin
   curDir := GetCurrentDir + '\photo';
   if opd.Execute() then begin
      new_fn := curDir+'\'+FormatDateTime('ddmmyy_hhmmss', now())+ExtractFileExt(opd.FileName);
      CopyFile(PChar(opd.FileName), (PChar(new_fn)), true);
      fMainEdit.qPhotoname.AsString := ExtractFileName(new_fn);
      Image1.Picture.LoadFromFile(new_fn);
   end;
end;

procedure TfPhotoEdit.FormShow(Sender: TObject);
   var
      curDir : string;
begin
   if fMainEdit.qPhotoname.AsString <> '' then begin
      curDir := GetCurrentDir + '\photo';
      Image1.Picture.LoadFromFile(curDir+'\'+fMainEdit.qPhotoname.AsString);
   end
   else begin
      Image1.Picture := nil;
   end;
end;

end.
