unit U_ImageShow;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBCtrls, cxControls, cxContainer, cxEdit, cxImage, cxDBEdit,
  siComp, siLngLnk, ExtCtrls, cxGraphics, cxLookAndFeels, cxLookAndFeelPainters;

type
  TF_ImageShow = class(TForm)
    ImageDB: TcxDBImage;
    lng_Forms: TsiLangLinked;
    Image: TImage;
    procedure ImageDBClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ImageClick(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
  private
    { Private declarations }
    GForm: TForm;
  public
    { Public declarations }
    Constructor Create(AOwner: TComponent; AForm: TForm);
    procedure ShowFromFile(const aFilePath: String; aPoint: PPoint=nil);
    Destructor  Destroy; override;
  end;

//var
  //F_ImageShow: TF_ImageShow;

implementation
Uses Unit_DM_SCS, U_Main;
{$R *.dfm}

procedure TF_ImageShow.FormCreate(Sender: TObject);
begin
    //Image.DataBinding.DataSource := TF_Main(GForm).DM.DataSource;
    //Image.DataBinding.DataField := 'PICTURE';
end;



constructor TF_ImageShow.Create(AOwner: TComponent; AForm: TForm);
begin
    GForm := AForm;
    inherited Create(AOwner);
end;

destructor TF_ImageShow.Destroy;
begin
    inherited;
end;

procedure TF_ImageShow.ImageDBClick(Sender: TObject);
begin
    Close;
end;

procedure TF_ImageShow.ShowFromFile(const aFilePath: String; aPoint: PPoint=nil);
begin
  ImageDB.visible := false;
  Image.Align := alClient;
  Image.visible := true;
  Image.Picture.LoadFromFile(aFilePath);
  Width := Image.Picture.Width + 1;
  Height := Image.Picture.Height + 1;
  Show;

  if aPoint <> nil then
  begin
    if (aPoint^.X + Width) > Screen.Width then
      Left := Screen.Width - Width
    else
      Left := aPoint^.X;
    Top := aPoint^.Y;
  end;
end;

procedure TF_ImageShow.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_ESCAPE then
    Hide;
end;

procedure TF_ImageShow.ImageClick(Sender: TObject);
begin
  Hide;
end;

procedure TF_ImageShow.FormDeactivate(Sender: TObject);
begin
  Hide;
end;

end.
