type
TMyNavigator = class(TObject)
private
FCurrent: Integer;
FMaxCount: Integer;
FMinCount: Integer;
FNextAction: TAction;
FPrevAction: TAction;
FSaveNextActionOnExecute: TNotifyEvent;
FSaveNextActionOnUpdate: TNotifyEvent;
FSavePrevActionOnExecute: TNotifyEvent;
FSavePrevActionOnUpdate: TNotifyEvent;
procedure SetCurrent(Value: Integer);
procedure SetMaxCount(Value: Integer);
procedure SetMinCount(Value: Integer);
procedure SetNextAction(Value: TAction);
procedure SetPrevAction(Value: TAction);
protected
procedure NextActionExecuted(Sender: TObject);
procedure NextActionUpdated(Sender: TObject);
procedure PrevActionExecuted(Sender: TObject);
procedure PrevActionUpdated(Sender: TObject);
public
destructor Destroy; override;
property Current: Integer read FCurrent write SetCurrent;
property MaxCount: Integer read FMaxCount write SetMaxCount;
property MinCount: Integer read FMinCount write SetMinCount;
property NextAction: TAction read FNextAction write SetNextAction;
property PrevAction: TAction read FPrevAction write SetPrevAction;
end;
...
{ TMyNavigator }
destructor TMyNavigator.Destroy;
begin
NextAction := nil;
PrevAction := nil;
inherited Destroy;
end;
procedure TMyNavigator.NextActionExecuted(Sender: TObject);
begin
Current := Current + 1;
if Assigned(FSaveNextActionOnExecute) then
FSaveNextActionOnExecute(Sender);
end;
procedure TMyNavigator.NextActionUpdated(Sender: TObject);
begin
FNextAction.Enabled := FCurrent < FMaxCount;
end;
procedure TMyNavigator.PrevActionExecuted(Sender: TObject);
begin
Current := Current - 1;
if Assigned(FSavePrevActionOnExecute) then
FSavePrevActionOnExecute(Sender);
end;
procedure TMyNavigator.PrevActionUpdated(Sender: TObject);
begin
FPrevAction.Enabled := FCurrent > FMinCount;
end;
procedure TMyNavigator.SetCurrent(Value: Integer);
begin
if FCurrent <> Value then
FCurrent := Max(FMinCount, Min(Value, FMaxCount));
end;
procedure TMyNavigator.SetMaxCount(Value: Integer);
begin
if FMaxCount <> Value then
begin
FMaxCount := Value;
FCurrent := Min(FCurrent, FMaxCount);
end;
end;
procedure TMyNavigator.SetMinCount(Value: Integer);
begin
if FMinCount <> Value then
begin
FMinCount := Value;
FCurrent := Max(FMinCount, FCurrent);
end;
end;
procedure TMyNavigator.SetNextAction(Value: TAction);
begin
if FNextAction <> Value then
begin
if Assigned(FNextAction) then
begin
FNextAction.OnExecute := FSaveNextActionOnExecute;
FNextAction.OnUpdate := FSaveNextActionOnUpdate;
end;
FNextAction := Value;
if Assigned(FNextAction) then
begin
FSaveNextActionOnExecute := FNextAction.OnExecute;
FSaveNextActionOnUpdate := FNextAction.OnUpdate;
FNextAction.OnExecute := NextActionExecuted;
FNextAction.OnUpdate := NextActionUpdated;
end;
end;
end;
procedure TMyNavigator.SetPrevAction(Value: TAction);
begin
if FPrevAction <> Value then
begin
if Assigned(FPrevAction) then
begin
FPrevAction.OnExecute := FSavePrevActionOnExecute;
FPrevAction.OnUpdate := FSavePrevActionOnUpdate;
end;
FPrevAction := Value;
if Assigned(FPrevAction) then
begin
FSavePrevActionOnExecute := FPrevAction.OnExecute;
FSavePrevActionOnUpdate := FPrevAction.OnUpdate;
FPrevAction.OnExecute := PrevActionExecuted;
FPrevAction.OnUpdate := PrevActionUpdated;
end;
end;
end;
Bookmarks