(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)

unit AHMDlgReg;

interface
{$I AHM.INC}
uses Classes,DesignIntf,
     AHMDialogs,
     AHMDialogClass,
     AHMTDBMemoView,
     AHMTDBPasswordDlg,
     AHMTPasswordDlg,
     AHMTPSDialog,
     AHMTQueryAccess,
     AHMTSerialNumber,
     AHMTShellAbout,
     AHMTTipTrickDlg,
     AHMTTextFileView,
     {$IFDEF AHMINPRISE3}
     AHMTFolderBrowser,
     {$ENDIF}
     AHMTDBImageView, DesignEditors;
type TAHMAboutDialogComponent = class(TPropertyEditor)
     public
       procedure Edit; override;
       function GetValue: string; override;
       function GetAttributes: TPropertyAttributes; override;
     end;
     TAHMDBStringProperty = class(TStringProperty)
     public
       function GetAttributes: TPropertyAttributes; override;
       procedure GetValueList(List: TStrings); virtual;
       procedure GetValues(Proc: TGetStrProc); override;
     end;
     TAHMDataFieldProperty = class(TAHMDBStringProperty)
     public
       function GetDataSourcePropName: string; virtual;
       procedure GetValueList(List: TStrings); override;
     end;
     TAHMExecDialogProperty = class(TStringProperty)
     public
       Procedure Edit; override;
       function GetValue: string; override;
       Function GetAttributes: TPropertyAttributes; override;
     end;
     TAHMDialogEditor = class(TDefaultEditor)
     public
       procedure ExecuteVerb(Index : Integer); override;
       function GetVerb(Index : Integer): string; override;
       function GetVerbCount : Integer; override;
       procedure Edit; override;
     end;

procedure Register;
implementation
uses Forms,Dialogs,SysUtils,TypInfo,DB, DBTables, DBCtrls;
{$R AHMDialogs.res}

procedure Register;
begin
  RegisterComponents('AHM Dialogs',[TAHMPasswordDlg,{$IFDEF AHMINPRISE3}TAHMFolderBrowser,{$ENDIF}TAHMPageSetupDialog,
                                        TAHMQueryAccess,TAHMSerialNumber,TAHMShellAbout,TAHMTipTricks,
                                        TAHMTextFileView]);
  RegisterComponents('AHM Data-Aware',[TAHMDBImageView,TAHMDBMemoView,TAHMDBPasswordDlg]);
  RegisterPropertyEditor(Typeinfo(TAHMExecDlgStr),TAHMPageSetupDialog,'DesignExecute',TAHMExecDialogProperty);
  RegisterPropertyEditor(TypeInfo(String),TComponent,'DataUsername',TAHMDataFieldProperty);
  RegisterPropertyEditor(TypeInfo(String),TComponent,'Datapassword',TAHMDataFieldProperty);
  RegisterPropertyEditor(TypeInfo(TAHMAboutDlgsStr),TComponent,'About',TAHMAboutDialogComponent);
  RegisterComponentEditor(TAHMDialogComponent,TAHMDialogEditor);
  RegisterComponentEditor(TAHMPageSetupDialog,TAHMDialogEditor);
end;

function TAHMDBStringProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList, paSortList, paMultiSelect];
end;

procedure TAHMDBStringProperty.GetValueList(List: TStrings);
begin
end;

procedure TAHMDBStringProperty.GetValues(Proc: TGetStrProc);
var
  I: Integer;
  Values: TStringList;
begin
  Values := TStringList.Create;
  try
    GetValueList(Values);
    for I := 0 to Values.Count - 1 do Proc(Values[I]);
  finally
    Values.Free;
  end;
end;

function TAHMDataFieldProperty.GetDataSourcePropName: string;
begin
  Result := 'DataSource';
end;

procedure TAHMDataFieldProperty.GetValueList(List: TStrings);
var
  Instance: TPersistent;
  PropInfo: PPropInfo;
  DataSource: TDataSource;
begin
  Instance := GetComponent(0);
  PropInfo := TypInfo.GetPropInfo(Instance.ClassInfo, GetDataSourcePropName);
  if (PropInfo <> nil) and (PropInfo^.PropType^.Kind = tkClass) then
  begin
    DataSource := TObject(GetOrdProp(Instance, PropInfo)) as TDataSource;
    if (DataSource <> nil) and (DataSource.DataSet <> nil) then
      DataSource.DataSet.GetFieldNames(List);
  end;
end;


procedure TAHMAboutDialogComponent.Edit;
begin
  ShowDialogsAbout;
end;

function TAHMAboutDialogComponent.GetValue: string;
begin
  FmtStr(Result, '(%s)', ['AHM Dialogs']);
end;

function TAHMAboutDialogComponent.GetAttributes: TPropertyAttributes;
begin
  Result := [paMultiSelect,paDialog,paReadOnly];
end;

Procedure TAHMExecDialogProperty.Edit;
begin
  if (GetComponent(0) is TAHMDialogComponent) then
  TAHMDialogComponent(GetComponent(0)).Execute else
  TAHMPageSetupDialog(GetComponent(0)).Execute;
end;

function TAHMExecDialogProperty.GetValue: string;
begin
  FmtStr(Result, '(%s)', ['Execute Test']);
end;


Function TAHMExecDialogProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog, paReadonly];
end;

procedure TAHMDialogEditor.ExecuteVerb(Index: Integer);
begin
  if (Index< 0) and (Index>2) then Exit;
  if index=0 then Edit;
  if index=1 then ShowDialogsAbout;
end;

function TAHMDialogEditor.GetVerb(Index: Integer): String;
begin
  if index=0 then  Result := 'Test '+Component.name;
  if index=1 then  Result := '(C)1995 - 1998 AHM';
end;

function TAHMDialogEditor.GetVerbCount: Integer;
begin
  Result:=2;
end;

procedure TAHMDialogEditor.Edit;
begin
  if (Component is TAHMDialogComponent) then
  TAHMDialogComponent(Component).Execute else
  TAHMPageSetupDialog(Component).Execute;
end;


end.
