(************************************************************************
*    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 AHMTMsgBoxHolder;
{$R AHMTMSGEx.res}
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls,StdCtrls,AHMSystemClass;
type
  TAHMMsgBoxHolder = class;
  TAHMMessagesEx = class;
  TAHMMessageEx = class;
  TAHMMessageExEvent = procedure (Sender:TObject;Var Message : String) of object;
  TAHMButtonClass = Class(TPersistent)
  private
    FCaption: String;
    FVisible: Boolean;
    FEnabled: Boolean;
    procedure SetCaption(const Value: String);
    procedure SetEnabled(const Value: Boolean);
    procedure SetVisible(const Value: Boolean);
    { Private declarations }
  public
    Constructor Create;
  published
    Property Caption : String read FCaption write SetCaption;
    Property Visible : Boolean read FVisible write SetVisible default True;
    Property Enabled : Boolean read FEnabled write SetEnabled default True;
  end;
  TAHMBaseButtonClass = Class(TAHMButtonClass)
  private
    FNumGlyphs: Integer;
    FGlyph: TBitmap;
    procedure SetGlyph(const Value: TBitmap);
    procedure SetNumGlyphs(const Value: Integer);
    { Private declarations }
  public
    Constructor Create;
    Destructor Destroy; override;
  published
    Property Glyph : TBitmap read FGlyph write SetGlyph;
    Property NumGlyphs : Integer read FNumGlyphs write SetNumGlyphs default 1;
  end;
  TAHMCheckButtonClass = Class(TAHMButtonClass)
  private
    FState: TCheckBoxState;
    FChecked: Boolean;
    FAllowGrayed: Boolean;
    procedure SetCheckboxstate(const Value: TCheckBoxState);
    procedure SetAllowGrayed(const Value: Boolean);
    procedure SetChecked(const Value: Boolean);
  protected
  public
    Constructor Create;
  published
    Property State : TCheckBoxState read FState write SetCheckboxstate default cbUnchecked;
    Property Checked : Boolean read FChecked write SetChecked default True;
    Property AllowGrayed : Boolean read FAllowGrayed write SetAllowGrayed default False;
  end;
  TAHMMsgButtonClass = Class(TAHMBaseButtonClass)
  private
    FModalResult: TModalResult;
    FDefault: Boolean;
    FMessage : TAHMMessageEx;
    procedure SetDefault(const Value: Boolean);
    Procedure OnChangeDefault(Sender : TObject);
  protected
  public
    Constructor Create(AMessage : TAHMMessageEx); virtual;
  published
    Property ModalResult : TModalResult read FModalResult write FModalResult default mrNone;
    Property Default : Boolean read FDefault write SetDefault default False;
  end;
  TAHMHelpButtonClass = Class(TAHMBaseButtonClass)
  private
    FHelpContext: LongInt;
  public
    Constructor Create;
  published
    property HelpContext : LongInt read FHelpContext write FHelpContext default 0;
  end;
  TAHMMessageEx = class(TCollectionItem)
  private
    FAHMMsgBoxHolder : TAHMMsgBoxHolder;
    FMessage: String;
    FCaption: String;
    FFont : TFont;
    FBeepType : TAHMBeeptype;
    FMsgButton1: TAHMMsgButtonClass;
    FMsgButton2: TAHMMsgButtonClass;
    FMsgButton3: TAHMMsgButtonClass;
    FHelpButton: TAHMHelpButtonClass;
    FCheckBox: TAHMCheckButtonClass;
    FButtonWidth: LongInt;
    FFormWidth: Integer;
    FOnCheckClick: TNotifyevent;
    FOnBtn1Click: TNotifyEvent;
    FOnBtn3Click: TNotifyEvent;
    FOnBtn2Click: TNotifyEvent;
    FOnHelpClick: TNotifyEvent;
    FMsgType: TMsgDlgType;
    FIcon: TIcon;
    FOnmrAll: TNotifyevent;
    FOnmrCancel: TNotifyevent;
    FOnmrYes: TNotifyevent;
    FOnmrIgnore: TNotifyevent;
    FOnmrNone: TNotifyevent;
    FOnmrYesToAll: TNotifyevent;
    FOnmrOk: TNotifyevent;
    FOnmrNoToAll: TNotifyevent;
    FOnmrNo: TNotifyevent;
    FOnmrRetry: TNotifyevent;
    FOnmrAbort: TNotifyevent;
    FBeforePopup: TAHMMessageExEvent;
    Procedure SetFont(Const Value : TFont);
    Procedure SetMessage(Const Value : String);
    { Private declarations }
    procedure SetButtonWidth(const Value: LongInt);
    procedure SetFormWidth(const Value: Integer);
    Procedure Button1Click(Sender : TObject);
    Procedure Button2Click(Sender : TObject);
    Procedure Button3Click(Sender : TObject);
    Procedure HelpButtonClick(Sender : TObject);
    Procedure CheckBoxClick(Sender : TObject);
    procedure SetMessageType(const Value: TMsgDlgType);
    procedure SetIcon(const Value: TIcon);
    procedure ProcessMessages(Value : TModalResult);
  protected
    function GetDisplayName: string; override;
  public
    constructor Create(Collection: TCollection); override;
    procedure Assign(Source: TPersistent); override;
    property Owner : TAHMMsgBoxHolder read FAHMMsgBoxHolder;
    property DisplayName : String read GetDisplayName;
    Destructor Destroy; override;
    { Public declarations }
    Function Execute : TModalResult;
    Function ForceExecute : TModalResult;
  published
    Property Buttonwidth : LongInt read FButtonWidth write SetButtonWidth default 80;
    Property Sound : TAHMBeeptype read FBeepType write FBeepType default bNone;
    Property MsgButton1 : TAHMMsgButtonClass read FMsgButton1 write FMsgButton1;
    Property MsgButton2 : TAHMMsgButtonClass read FMsgButton2 write FMsgButton2;
    Property MsgButton3 : TAHMMsgButtonClass read FMsgButton3 write FMsgButton3;
    Property MsgType : TMsgDlgType read FMsgType write SetMessageType default mtInformation;
    Property HelpButton : TAHMHelpButtonClass read FHelpButton write FHelpButton;
    Property CheckBox : TAHMCheckButtonClass read FCheckBox write FCheckBox;
    Property FormWidth : Integer read FFormWidth write SetFormWidth default 320;
    Property Message : String read FMessage write SetMessage;
    Property CustomIcon : TIcon read FIcon write SetIcon;
    Property Caption : String read FCaption write FCaption;
    Property Font : TFont read FFont write SetFont;
    property BeforePopup : TAHMMessageExEvent read FBeforePopup write FBeforePopup;
    Property OnCheckClick : TNotifyevent read FOnCheckClick write FOnCheckClick;
    Property OnBtn1Click : TNotifyEvent read FOnBtn1Click write FOnBtn1Click;
    Property OnBtn2Click : TNotifyEvent read FOnBtn2Click write FOnBtn2Click;
    Property OnBtn3Click : TNotifyEvent read FOnBtn3Click write FOnBtn3Click;
    Property OnHelpClick : TNotifyEvent read FOnHelpClick write FOnHelpClick;
    Property OnmrNone : TNotifyevent read FOnmrNone write FOnmrNone;
    Property OnmrAbort : TNotifyevent read FOnmrAbort write FOnmrAbort;
    Property OnmrAll : TNotifyevent read FOnmrAll write FOnmrAll;
    Property OnmrCancel : TNotifyevent read FOnmrCancel write FOnmrCancel;
    Property OnmrIgnore : TNotifyevent read FOnmrIgnore write FOnmrIgnore;
    Property OnmrNo : TNotifyevent read FOnmrNo write FOnmrNo;
    Property OnmrOk : TNotifyevent read FOnmrOk write FOnmrOk;
    Property OnmrRetry : TNotifyevent read FOnmrRetry write FOnmrRetry;
    Property OnmrYes : TNotifyevent read FOnmrYes write FOnmrYes;
    Property OnmrNoToAll : TNotifyevent read FOnmrNoToAll write FOnmrNoToAll;
    Property OnmrYesToAll : TNotifyevent read FOnmrYesToAll write FOnmrYesToAll;
  end;
  TAHMMessagesEx = class(TCollection)
  private
    FAHMMsgBoxHolder : TAHMMsgBoxHolder;
    function GetAHMMessageEx(Index: Integer): TAHMMessageEx;
    procedure SetAHMMessageEx(Index: Integer; Value: TAHMMessageEx);
  protected
    function GetOwner : TPersistent; override;
  public
    constructor Create(AOwner: TAHMMsgBoxHolder);
    function Add : TAHMMessageEx;
   Function Delete(Index :Integer) :Boolean;
    property Owner : TAHMMsgBoxHolder read FAHMMsgBoxHolder;
    property Items[Index: Integer]: TAHMMessageEx
             read GetAHMMessageEx write SetAHMMessageEx; default;
  end;
  TAHMMsgBoxHolder = class(TAHMSystemsComponent)
  private
    FAHMMessagesEx : TAHMMessagesEx;
    FBeforePopup: TAHMMessageExEvent;
    procedure SetAHMMessagesEx(Value: TAHMMessagesEx);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    Function Execute(Index : Integer) : TModalResult;
    Function ForceExecute(Index : Integer) : TModalResult;
  published
    property BeforePopup : TAHMMessageExEvent read FBeforePopup write FBeforePopup;
    property Messages: TAHMMessagesEx read FAHMMessagesEx write SetAHMMessagesEx;
  end;

implementation

uses Buttons;

Type TAHMMsgForm = class(TForm)
     private
       MsgText : String;
       CheckBox:TCheckBox;
       MyTxtRect : TRect;
       Procedure SetupSelf;
       Procedure SelfPaint(Sender : TObject);
       Procedure OnSelfShow(Sender : TObject);
     protected
     public
     published
       FAHMMessageEx : TAHMMessageEx;
     end;
var
  AHMMsgForm : TAHMMsgForm = nil;


procedure TAHMMsgForm.SelfPaint(Sender : TObject);
Var Myrect : TRect;
begin
  Font:=FAHMMessageEx.FFont;
  MyRect:=Clientrect;
  InflateRect(MyRect,-10,-10);
  if (FAHMMessageEx.FIcon.Empty) and (FAHMMessageEx.FMsgType=mtCustom) then MyRect.Left:=14 else
  MyRect.Left:=MyRect.Left+47;
  MyRect.Right:=MyRect.Right-FAHMMessageEx.FButtonwidth-18;
  SetBkMode(Canvas.Handle,Transparent);
  DrawText(Canvas.Handle,PChar(MsgText),-1,myrect,DT_LEFT or DT_WORDBREAK or DT_CALCRECT);
  if MyRect.Bottom-MyRect.Top<(5*(Self.Canvas.TextHeight('W')+10)) then
  begin
    Clientheight:=(6*(Self.Canvas.TextHeight('W')+10));
  end else
  begin
    ClientHeight:=MyRect.Bottom-MyRect.Top+(1*(Self.Canvas.TextHeight('W')+10));
  end;
  DrawText(Canvas.Handle,PChar(MsgText),-1,myrect,DT_LEFT or DT_WORDBREAK);
  InFlateRect(MyRect,5,5);
  MyTxtRect:=MyRect;
  MyTxtRect.Right:=ClientWidth-FAHMMessageEx.FButtonWidth-5;
end;

procedure TAHMMsgForm.OnSelfShow(Sender: TObject);
begin
  case FAHMMessageEx.FBeepType of
    bDefault      : MessageBeep(MB_OK);
    bAsterix      : MessageBeep(MB_ICONAsterisk);
    bExclamation  : MessageBeep(MB_ICONEXCLAMATION);
    bQuestion     : MessageBeep(MB_ICONQUESTION);
    bCriticalStop : MessageBeep(MB_ICONHAND);
  end;
end;

Procedure TAHMMsgForm.SetupSelf;
Var I : Integer;
begin
  BorderStyle:=bsDialog;
  Caption:=FAHMMessageEx.FCaption;
  Position:=poScreenCenter;
  ClientWidth:=FAHMMessageEx.FFormWidth;
  ClientHeight:=200;
  KeyPreview:=True;
  SelfPaint(Self);
  with TBitBtn.Create(self) do
  begin
    Parent:=self;
    Width:=FAHMMessageEx.FButtonWidth;
    Height:=Self.Canvas.TextHeight('W')+10;
    Left:=Self.ClientWidth-FAHMMessageEx.FButtonWidth-5;
    Top:=4;
    ModalResult:=FAHMMessageEx.MsgButton1.FModalResult;
    Caption:=FAHMMessageEx.MsgButton1.FCaption;
    Visible:=FAHMMessageEx.MsgButton1.FVisible;
    Enabled:=FAHMMessageEx.MsgButton1.Enabled;
    Default:=FAHMMessageEx.MsgButton1.Default;
    Glyph:=FAHMMessageEx.MsgButton1.FGlyph;
    NumGlyphs:=FAHMMessageEx.MsgButton1.FNumGlyphs;
    OnClick:=FAHMMessageEx.Button1Click;
  end;
  with TBitBtn.Create(self) do
  begin
    Parent:=self;
    Width:=FAHMMessageEx.FButtonWidth;
    Height:=Self.Canvas.TextHeight('W')+10;
    Left:=Self.ClientWidth-FAHMMessageEx.FButtonWidth-5;
    Top:=6+(Self.Canvas.TextHeight('W')+10);
    ModalResult:=FAHMMessageEx.MsgButton2.FModalResult;
    Caption:=FAHMMessageEx.MsgButton2.FCaption;
    Visible:=FAHMMessageEx.MsgButton2.FVisible;
    Enabled:=FAHMMessageEx.MsgButton2.Enabled;
    Default:=FAHMMessageEx.MsgButton2.Default;
    Glyph:=FAHMMessageEx.MsgButton2.FGlyph;
    NumGlyphs:=FAHMMessageEx.MsgButton2.FNumGlyphs;
    OnClick:=FAHMMessageEx.Button2Click;
  end;
  with TBitBtn.Create(self) do
  begin
    Parent:=self;
    Width:=FAHMMessageEx.FButtonWidth;
    Height:=Self.Canvas.TextHeight('W')+10;
    Left:=Self.ClientWidth-FAHMMessageEx.FButtonWidth-5;
    Top:=8+(2*(Self.Canvas.TextHeight('W')+10));
    ModalResult:=FAHMMessageEx.MsgButton3.FModalResult;
    Caption:=FAHMMessageEx.MsgButton3.FCaption;
    Visible:=FAHMMessageEx.MsgButton3.FVisible;
    Enabled:=FAHMMessageEx.MsgButton3.Enabled;
    Default:=FAHMMessageEx.MsgButton3.Default;
    Glyph:=FAHMMessageEx.MsgButton3.FGlyph;
    NumGlyphs:=FAHMMessageEx.MsgButton3.FNumGlyphs;
    OnClick:=FAHMMessageEx.Button3Click;
  end;
  with TBitBtn.Create(self) do
  begin
    Parent:=self;
    Width:=FAHMMessageEx.FButtonWidth;
    Height:=Self.Canvas.TextHeight('W')+10;
    Left:=Self.ClientWidth-FAHMMessageEx.FButtonWidth-5;
    Top:=10+(3*(Self.Canvas.TextHeight('W')+10));;
    Caption:=FAHMMessageEx.HelpButton.FCaption;
    Visible:=FAHMMessageEx.HelpButton.FVisible;
    Enabled:=FAHMMessageEx.HelpButton.Enabled;
    Glyph:=FAHMMessageEx.HelpButton.FGlyph;
    NumGlyphs:=FAHMMessageEx.HelpButton.FNumGlyphs;
    OnClick:=FAHMMessageEx.HelpButtonClick;
  end;
  with TImage.Create(self) do
  begin
    Parent:=self;
    Transparent:=True;
    Width:=32;
    Height:=32;
    Left:=15;
    Top:=10;
    if assigned(FAHMMessageEx.FIcon) and (not FAHMMessageEx.FIcon.Empty) and (FAHMMessageEx.MsgType=mtCustom) then
    begin
      Picture.Icon:=FAHMMessageEx.FIcon;
    end else
    case FAHMMessageEx.FMsgType of
      mtError : Picture.Bitmap.LoadFromResourceName(HInstance,'AHMMSGEXERROR');
      mtInformation : Picture.Bitmap.LoadFromResourceName(HInstance,'AHMMSGEXINFORMATION');
      mtConfirmation : Picture.Bitmap.LoadFromResourceName(HInstance,'AHMMSGEXCONFIRMATION');
      mtWarning : Picture.Bitmap.LoadFromResourceName(HInstance,'AHMMSGEXWARNING');
    else
    end;
  end;
  with TBevel.Create(Self) do
  begin
    Parent:=Self;
    Shape:=bsFrame;
    Left:=5;
    Top:=5;
    Height:=Self.ClientHeight-(Self.Canvas.TextHeight('W')+8)-MyTxtRect.Top;
    Width :=Self.ClientWidth-FAHMMessageEx.FButtonWidth-15;
  end;
  CheckBox:=TCheckbox.Create(self);
  with CheckBox do
  begin
    Parent:=self;
    Width:=self.ClientWidth-2;
    Height:=Self.Canvas.TextHeight('W')+2;
    Left:=2;
    Top:=Self.ClientHeight-(Self.Canvas.TextHeight('W')+4);
    AllowGrayed:=FAHMMessageEx.CheckBox.FAllowGrayed;
    State:=FAHMMessageEx.CheckBox.FState;
    Checked:=FAHMMessageEx.CheckBox.FChecked;
    Caption:=FAHMMessageEx.CheckBox.FCaption;
    Visible:=FAHMMessageEx.CheckBox.FVisible;
    Enabled:=FAHMMessageEx.CheckBox.Enabled;
    OnClick:=FAHMMessageEx.CheckBoxClick;
  end;
  for I:=0 to Self.ComponentCount-1 do
   if (Components[I] is TBitBtn) then
     if (Components[I] as TBitBtn).Default then
       ActiveControl:=(Components[I] as TBitBtn);
end;

Function TAHMMessageEx.Execute : TModalResult;
begin
  if not(CheckBox.Checked) then
  begin
    Result:=mrNone;
    Exit;
  end;
  AHMMsgForm:=TAHMMsgForm.CreateNew(Application);
  AHMMsgForm.MsgText:=FMessage;
  if assigned(FBeforePopup) then FBeforePopup(self,AHMMsgForm.MsgText);
  if assigned(FAHMMsgBoxHolder.FBeforePopup) then FAHMMsgBoxHolder.FBeforePopup(self,AHMMsgForm.MsgText);
  with AHMMsgForm do
  try
    FAHMMessageEx:=self;
    SetUpSelf;
    OnPaint:=SelfPaint;
    OnShow:=OnSelfShow;
    result:=showmodal;
  finally
    free;
  end;
  AHMMsgForm:=nil;
  ProcessMessages(result);
end;

function TAHMMessageEx.ForceExecute: TModalResult;
begin
  AHMMsgForm:=TAHMMsgForm.CreateNew(Application);
  AHMMsgForm.MsgText:=FMessage;
  if assigned(FBeforePopup) then FBeforePopup(self,AHMMsgForm.MsgText);
  if assigned(FAHMMsgBoxHolder.FBeforePopup) then FAHMMsgBoxHolder.FBeforePopup(self,AHMMsgForm.MsgText);
  with AHMMsgForm do
  try
    FAHMMessageEx:=self;
    SetUpSelf;
    OnPaint:=SelfPaint;
    OnShow:=OnSelfShow;
    CheckBox.Enabled:=False;
    result:=showmodal;
  finally
    free;
  end;
  AHMMsgForm:=nil;
  ProcessMessages(result);
end;

Destructor TAHMMessageEx.Destroy;
begin
  FIcon.Free;
  FCheckBox.Free;
  FHelpButton.Free;
  FMsgButton1.Free;
  FMsgButton2.Free;
  FMsgButton3.Free;
  FFont.Free;
  inherited Destroy;
end;

Procedure TAHMMessageEx.SetFont(Const Value : TFont);
begin
  FFont.Assign(Value);
end;

Procedure TAHMMessageEx.SetMessage(Const Value : String);
begin
  FMessage:=Value;
end;

{ TAHMButtonClass }

constructor TAHMBaseButtonClass.Create;
begin
  inherited Create;
  FGlyph:=TBitmap.Create;
  FNumGlyphs:=1;
end;

destructor TAHMBaseButtonClass.Destroy;
begin
  FGlyph.Free;
  inherited Destroy;
end;

procedure TAHMButtonClass.SetCaption(const Value: String);
begin
  FCaption := Value;
end;

procedure TAHMButtonClass.SetEnabled(const Value: Boolean);
begin
  FEnabled := Value;
end;

procedure TAHMBaseButtonClass.SetGlyph(const Value: TBitmap);
begin
  FGlyph.assign(Value);
end;

procedure TAHMBaseButtonClass.SetNumGlyphs(const Value: Integer);
begin
  FNumGlyphs := Value;
end;

procedure TAHMButtonClass.SetVisible(const Value: Boolean);
begin
  FVisible := Value;
end;

{ TAHMHelpButtonClass }

constructor TAHMHelpButtonClass.Create;
begin
  inherited Create;
  FHelpContext:=0;
end;

{ TAHMMsgButtonClass }

constructor TAHMMsgButtonClass.Create(AMessage : TAHMMessageEx);
begin
  inherited Create;
  FMessage:=AMessage;
  FModalResult:=mrNone;
end;

procedure TAHMMsgButtonClass.OnChangeDefault(Sender: TObject);
begin
  if (Sender is TAHMMsgButtonClass) then
  begin
    FMessage.MsgButton1.FDefault:=False;
    FMessage.MsgButton2.FDefault:=False;
    FMessage.MsgButton3.FDefault:=False;
    TAHMMsgButtonClass(Sender).FDefault:=True;
  end;
end;

procedure TAHMMsgButtonClass.SetDefault(const Value: Boolean);
begin
  FDefault:=Value;
  if Value then OnChangeDefault(Self);
end;

{ TAHMBaseButtonClass }

constructor TAHMButtonClass.Create;
begin
  inherited Create;
  FVisible:=True;
  FCaption:='MsgBtn';
  FEnabled:=True;
end;

{ TAHMCheckButtonClass }

constructor TAHMCheckButtonClass.Create;
begin
  inherited Create;
  FAllowgrayed:=False;
  FChecked:=True;
  FState:=cbUnChecked;
end;

procedure TAHMCheckButtonClass.SetAllowGrayed(const Value: Boolean);
begin
  FAllowGrayed := Value;
  if AHMMsgForm<>nil then AHMMsgForm.Checkbox.AllowGrayed:=Value;
end;

procedure TAHMCheckButtonClass.SetCheckboxstate(const Value: TCheckBoxState);
begin
  FState := Value;
  if AHMMsgForm<>nil then AHMMsgForm.Checkbox.State:=Value;
end;

procedure TAHMCheckButtonClass.SetChecked(const Value: Boolean);
begin
  FChecked := Value;
  if AHMMsgForm<>nil then AHMMsgForm.Checkbox.Checked:=Value;
end;

procedure TAHMMessageEx.SetButtonWidth(const Value: LongInt);
begin
  FButtonWidth := Value;
end;

procedure TAHMMessageEx.SetFormWidth(const Value: Integer);
begin
  if Value>=320 then FFormWidth := Value;
end;

procedure TAHMMessageEx.Button1Click(Sender: TObject);
begin
  if assigned(FOnBtn1Click) then FOnBtn1Click(self);
end;

procedure TAHMMessageEx.Button2Click(Sender: TObject);
begin
  if assigned(FOnBtn2Click) then FOnBtn2Click(self);
end;

procedure TAHMMessageEx.Button3Click(Sender: TObject);
begin
  if assigned(FOnBtn3Click) then FOnBtn3Click(self);
end;

procedure TAHMMessageEx.CheckBoxClick(Sender: TObject);
begin
  Self.Checkbox.State:=AHMMsgForm.Checkbox.State;
  Self.Checkbox.Checked:=AHMMsgForm.Checkbox.Checked;
  if assigned(FOnCheckClick) then FOnCheckClick(Self);
end;

procedure TAHMMessageEx.HelpButtonClick(Sender: TObject);
begin
  Application.HelpContext(FHelpButton.FHelpContext);
  if assigned(FOnHelpClick) then FOnHelpClick(self);
end;

procedure TAHMMessageEx.SetMessageType(const Value: TMsgDlgType);
begin
  FMsgType := Value;
end;


procedure TAHMMessageEx.SetIcon(const Value: TIcon);
begin
  FIcon.assign(Value);
end;

constructor TAHMMessageEx.Create(Collection: TCollection);
begin
  inherited Create(Collection);
  FAHMMsgBoxHolder :=(((Collection as TAHMMessagesEx).GetOwner)
                                          as TAHMMsgBoxHolder);
  FFont:=TFont.Create;
  FMsgButton3:=TAHMMsgButtonClass.Create(Self);
  FMsgButton3.FCaption:='&Custom..';
  FMsgButton2:=TAHMMsgButtonClass.Create(Self);
  FMsgButton2.FCaption:='&Cancel';
  FMsgButton1:=TAHMMsgButtonClass.Create(Self);
  FMsgButton1.FCaption:='&Ok';
  FHelpButton:=TAHMHelpButtonClass.Create;
  FHelpButton.FCaption:='&Help';
  FCheckBox:=TAHMCheckButtonClass.Create;
  FCheckBox.FCaption:='Show this Dialog the next time this event occurs ?';
  FCaption:='My Caption';
  FMsgType:=mtInformation;
  FIcon:=TIcon.Create;
  FBeepType:=bNone;
  FButtonWidth:=80;
  FFormWidth:=320;
end;

function TAHMMessageEx.GetDisplayName: string;
begin
{  Result := 'Alex';
  if Result = '' then}
  Result := inherited GetDisplayName;
  if FMessage<>'' then Result:=FMessage
    else Result:='No message defined';
  {Other than Delphi3 -> if Result = '' then Result := 'TAHMADFIELD';}
end;

function TAHMMessagesEx.GetOwner: TPersistent;
begin
  Result := FAHMMsgBoxHolder;
end;

procedure TAHMMessageEx.Assign(Source: TPersistent);
begin
  if Source is TAHMMessageEx then
  begin
    Exit;
  end;
  inherited Assign(Source);
end;

constructor TAHMMessagesEx.Create(AOwner: TAHMMsgBoxHolder);
begin
  inherited Create(TAHMMessageEx);
  FAHMMsgBoxHolder := AOwner;
end;

function TAHMMessagesEx.Add: TAHMMessageEx;
begin
  Result := TAHMMessageEx(inherited Add);
end;

function TAHMMessagesEx.GetAHMMessageEx(Index: Integer): TAHMMessageEx;
begin
  Result := TAHMMessageEx(inherited GetItem(Index));
end;

procedure TAHMMessagesEx.SetAHMMessageEx(Index: Integer; Value: TAHMMessageEx);
begin
  inherited SetItem(Index, Value);
end;

constructor TAHMMsgBoxHolder.Create(AOwner: TComponent);
begin
  inherited create(AOwner);
  FAHMMessagesEx:=TAHMMessagesEx.Create(self);
end;

destructor TAHMMsgBoxHolder.Destroy;
begin
  FAHMMessagesEx.Free;
  inherited Destroy;
end;

function TAHMMsgBoxHolder.Execute(Index: Integer): TModalResult;
begin
  if (Index>-1) and (Index<FAHMMessagesEx.Count) then
  result:=FAHMMessagesEx[Index].Execute else result:=mrNone;
end;

function TAHMMsgBoxHolder.ForceExecute(Index: Integer): TModalResult;
begin
  if (Index>-1) and (Index<FAHMMessagesEx.Count) then
  result:=FAHMMessagesEx[Index].ForceExecute else result:=mrNone;
end;

procedure TAHMMsgBoxHolder.SetAHMMessagesEx(Value: TAHMMessagesEx);
begin
  FAHMMessagesEx.Assign(Value);
end;


function TAHMMessagesEx.Delete(Index: Integer): Boolean;
begin
  result := true;
  Try
    Items[Index].free;
  Except
    result := false;
    Application.handleexception(self);
  End;
end;

procedure TAHMMessageEx.ProcessMessages(Value: TModalResult);
begin
  case Value of
    mrAll : if assigned(FOnmrAll) then  FOnmrAll(Self);
    mrCancel : if assigned(FOnmrCancel) then  FOnmrCancel(Self);
    mrYes : if assigned(FOnmrYes) then  FOnmrYes(Self);
    mrIgnore : if assigned(FOnmrIgnore) then  FOnmrIgnore(Self);
    mrNone : if assigned(FOnmrNone) then  FOnmrNone(Self);
    mrYesToAll : if assigned(FOnmrYesToAll) then  FOnmrYesToAll(Self);
    mrOk : if assigned(FOnmrOk) then  FOnmrOk(Self);
    mrNoToAll : if assigned(FOnmrNoToAll) then  FOnmrNoToAll(Self);
    mrNo : if assigned(FOnmrNo) then  FOnmrNo(Self);
    mrRetry : if assigned(FOnmrRetry) then  FOnmrRetry(Self);
    mrAbort : if assigned(FOnmrAbort) then  FOnmrAbort(Self);
  else
    if assigned(FOnmrNone) then  FOnmrNone(Self);
  end;
end;

end.
