unit frbaseframe;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, XMLPropStorage, MSSQLConn, SQLDB, Contnrs;


type
  TAFConnection = TMSSQLConnection;

  TFrameBase = class;

  TSelectEvent = procedure(AFrame: TFrameBase) of object;
  TCheckConnectionEvent = procedure(AConnection: TAFConnection; var IsOk:Boolean) of object;


  { TFrameBase }

  TFrameBase = class(TFrame)
  private
    FBenutzerName: String;
    FOnCheckConnection: TCheckConnectionEvent;
    FOnSelect: TSelectEvent; //Method Pointer
    FOnUnSelect: TSelectEvent;
    FSelected: Boolean;
    FCon: TAFConnection;
    FInit: Boolean;
    FXMLPropStorage : TXMLPropStorage;
    function GetXMLPropStorage: TXMLPropStorage;
    procedure SetBenutzerName(AValue: String);
    procedure SetXMLPropStorage(AValue: TXMLPropStorage);
  protected
    procedure DoSelect; //Dispatch Method
    procedure DoUnSelect;
    function GetCon: TAFConnection; virtual;
    procedure SetCon(AValue: TAFConnection); virtual;
    function CheckConnection: Boolean; virtual;
  public
    constructor Create(AOwner: TComponent); override;
    constructor Create(AOwner: TComponent; AParent: TWinControl; AAlign: TAlign = alClient); virtual;
    procedure Select; virtual;
    procedure UnSelect; virtual;
    property Selected: Boolean read FSelected write FSelected;
    property OnSelect: TSelectEvent read FOnSelect write FOnSelect;
    property OnUnSelect: TSelectEvent read FOnUnSelect write FOnUnSelect;
    property OnCheckConnection: TCheckConnectionEvent read FOnCheckConnection write FOnCheckConnection;
  published
    property Connection: TAFConnection read GetCon write SetCon;
    property XMLPropStorage : TXMLPropStorage read GetXMLPropStorage write SetXMLPropStorage;
    property IsInitDone : Boolean read FInit write FInit;
    property BenutzerName : String read FBenutzerName write SetBenutzerName;
  end;

implementation

{$R *.lfm}

{ TFrameBase }

function TFrameBase.GetCon: TAFConnection;
begin
  Result := FCon;
end;

procedure TFrameBase.SetCon(AValue: TAFConnection);
begin
  if FCon=AValue then Exit;
  FCon:=AValue;
end;

function TFrameBase.CheckConnection:Boolean;
begin
  Result:= true;
  if Assigned(FOnCheckConnection) then
      FOnCheckConnection(FCon,Result);
end;

constructor TFrameBase.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FXMLPropStorage:= nil;
  FOnSelect:=nil;
  FSelected:=False;
  FCon:=nil;
  FOnCheckConnection:= nil;
  FInit := False;
  FBenutzerName:= 'U.N.Known';
end;

constructor TFrameBase.Create(AOwner: TComponent; AParent: TWinControl;
  AAlign: TAlign);
begin
  Create(AOwner);
  Parent:= AParent;
  Align:= AAlign;
end;

function TFrameBase.GetXMLPropStorage: TXMLPropStorage;
begin
  Result:=FXMLPropStorage;
end;

procedure TFrameBase.SetBenutzerName(AValue: String);
begin
  if FBenutzerName=AValue then Exit;
  FBenutzerName:=AValue;
end;

procedure TFrameBase.SetXMLPropStorage(AValue: TXMLPropStorage);
begin
  if FXMLPropStorage=AValue then Exit;
  FXMLPropStorage:=AValue;
end;

procedure TFrameBase.DoSelect;
begin
  if not FSelected then
    if Assigned(FOnSelect) then
      FOnSelect(Self);
end;

procedure TFrameBase.DoUnSelect;
begin
  if FSelected then
    if Assigned(FOnUnSelect) then
      FOnUnSelect(Self);
end;

procedure TFrameBase.Select;
begin
  DoSelect;
  FSelected:= True;
end;

procedure TFrameBase.UnSelect;
begin
  DoUnSelect;
  FSelected:= False;
end;

end.
