unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
THotkeyCollectionItem =
class;
THotkeyCollection =
class(TCollection)
private
FOwner: TPersistent;
function GetItem(
Index: Integer): THotkeyCollectionItem;
procedure SetItem(
Index: Integer; Value: THotkeyCollectionItem);
protected
function GetOwner: TPersistent;
override;
public
constructor Create(AOwner: TPersistent);
function Add: THotkeyCollectionItem;
property Items[
Index: Integer]: THotkeyCollectionItem
read GetItem
write SetItem;
default;
end;
THotkeyCollectionItem =
class(TCollectionItem)
private
FHotkey: TShortcut;
FAction: Cardinal;
FSendKey: TShortcut;
FSendAction: Cardinal;
public
constructor Create(Collection: TCollection);
override;
published
property Hotkey: TShortcut
read FHotkey
write FHotkey;
property Action: Cardinal
read FAction
write FAction;
property SendKey: TShortcut
read FSendKey
write FSendKey;
property SendAction: Cardinal
read FSendAction
write FSendAction;
end;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
Collection: THotkeyCollection;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
MessageBox(
Handle, PChar(IntToStr(Collection.Add.
Index)), '
', 0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Collection := THotkeyCollection.Create(Application);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Collection.Free;
end;
{ TMyCollection }
constructor THotkeyCollection.Create(AOwner: TPersistent);
begin
inherited Create(THotkeyCollectionItem);
FOwner := AOwner;
end;
function THotkeyCollection.Add: THotkeyCollectionItem;
begin
Result := THotkeyCollectionItem(
inherited Add);
end;
function THotkeyCollection.GetItem(
Index: Integer): THotkeyCollectionItem;
begin
Result := THotkeyCollectionItem(
inherited GetItem(
Index));
end;
function THotkeyCollection.GetOwner: TPersistent;
begin
Result := FOwner;
end;
procedure THotkeyCollection.SetItem(
Index: Integer; Value: THotkeyCollectionItem);
begin
inherited SetItem(
Index, Value);
end;
{ TMyCollectionItem }
constructor THotkeyCollectionItem.Create(Collection: TCollection);
begin
FHotkey := 49217;
FAction := 0;
FSendKey := 49217;
FSendAction := 0;
end;
end.