📄 delphiwizard.pas
字号:
// ***************************************************************
// TDelphiWizard v1.1
// (C) 1998 Marc Nieuwhof, MNIWare
//
//
// Description:
//
// TDelphiWizard is a simple component that enables
// you to create Wizards like the 'Add new hardware' wizard.
// It only needs a TNotebook (On the Win31 tab) that it will
// control with a Back, Next, Finish and Help button.
// TDelphiWizard will let you enter the captions of the buttons
// so that you can use them in your own language.
// It also has 5 events for more user interaction.
//
// This component is totally FREEware and I encourage
// you to add/modify some things for you own needs.
// If you redistribute your modified version I would
// like to have it to see what you've done!
//
// Send mail to: m.nieuwhof@hs-ipabo.edu or
// alfons@xs4all.nl
//
// ***************************************************************
//
// Properties:
//
// BackCaption: Caption of the Back button
// Defaults to: < Back
//
// NextCaption: Caption of the Next button
// Defaults to: Next >
//
// AbortCaption: Caption of the End button
// Defaults to: Cancel
//
// ReadyCaption: Caption of the End button when
// TDelphiWizard is at the last page
// Defaults to: Finish
//
// HelpCaption: Caption of the Help button
// Defaults to: Help
//
// Notebook: A TNoteBook (Win31 tab)
//
// Ready: Readonly... True when ready!
//
// EnableHelp: Enables/Disables the Help button
//
// Events:
//
// OnBackClick: Triggered when clicked on the Back button
// OnNextClick: Triggered when clicked on the Next button
// OnEndClick: Triggered when clicked on the End button
// OnHelpClick: Triggered when clicked on the Help button
// OnPageChange: Triggered when a paged was changed
//
// Usage:
//
// Drop TDelphiWizard on your form.
// It will autoalign to the bottom of your form.
// Drop a TNotebook component on your form and
// set the align property to alClient.
// Add pages and components to the TNotebook and
// assign it to the NoteBook property of TDelphiWizard.
// Run the project!!
//
// Additional notes:
//
// If you assigned a TNotebook without pages, one page
// or no TNotebook at all, the Back and Next button will
// be disabled!
//
// ***************************************************************
unit DelphiWizard;
interface
uses
Messages,
Classes,
Graphics,
Controls,
StdCtrls,
ExtCtrls;
type
TDelphiWizard = class(TCustomControl)
private
{ Private declarations }
FNoteBook: TNoteBook; // Notebook component
BackButton: TButton; // Back button
EndButton: TButton; // Next button
NextButton: TButton; // Finish button
HelpButton: TButton; // Help button
FEnableHelp: Boolean; // Enable/Disable help button
FBackCaption: String; // Backbutton caption
FNextCaption: String; // Nextbutton caption
FAbortCaption: String; // Cancel button caption
FReadyCaption: String; // Ready button caption
FHelpCaption: String; // Help button caption
FPageName: String; // Name of current page
FReady: Boolean; // Ready state of Wizard
FOnBackClick: TNotifyEvent; // Event when back clicked
FOnNextClick: TNotifyEvent; // Event when Next clicked
FOnEndClick: TNotifyEvent; // Event when Finish clicked
FOnHelpClick: TNotifyEvent; // Event when Help clicked
FOnPageChange: TNotifyEvent; // Event when page changed
protected
{ Protected declarations }
Procedure Paint; Override;
Procedure SetNoteBook (Value: TNoteBook);
Procedure SetBackCaption (Caption: String);
Procedure SetNextCaption (Caption: String);
Procedure SetAbortCaption (Caption: String);
Procedure SetReadyCaption (Caption: String);
Procedure SetHelpCaption (Caption: String);
Procedure Notification (AComponent: TComponent; Operation: TOperation); override;
// Clickers
Procedure BackClick(Sender: TObject);
Procedure NextClick(Sender: TObject);
Procedure EndClick (Sender: TObject);
Procedure HelpClick(Sender: TObject);
public
{ Public declarations }
Constructor Create(AOwner: TComponent); Override;
Destructor Destroy; Override;
Property PageName: String Read FPageName;
Property Ready: Boolean Read FReady;
published
{ Published declarations }
Property EnableHelp: Boolean Read FEnableHelp Write FEnableHelp;
Property NoteBook: TNoteBook Read FNoteBook Write SetNoteBook;
Property BackCaption: String Read FBackCaption Write SetBackCaption;
Property NextCaption: String Read FNextCaption Write SetNextCaption;
Property AbortCaption: String Read FAbortCaption Write SetAbortCaption;
Property ReadyCaption: String Read FReadyCaption Write SetReadyCaption;
Property HelpCaption: String Read FHelpCaption Write SetHelpCaption;
Property OnBackClick: TNotifyEvent Read FOnBackClick Write FOnBackClick;
Property OnNextClick: TNotifyEvent Read FOnNextClick Write FOnNextClick;
Property OnEndClick: TNotifyEvent Read FOnEndClick Write FOnEndClick;
Property OnHelpClick: TNotifyEvent Read FOnHelpClick Write FOnHelpClick;
Property OnPageChange: TNotifyEvent Read FOnPageChange Write FOnPageChange;
end;
procedure Register;
implementation
//
// Register the component
//
procedure Register;
begin
RegisterComponents('MNIware', [TDelphiWizard]);
end;
//
// TDelphiWizard: Create
//
Constructor TDelphiWizard.Create(AOwner: TComponent);
Begin
// Component initialisation
Inherited Create(Aowner);
Align:=alBottom;
Height:=44;
FReady:=False;
FEnableHelp:=True;
// Create the buttons
// Back button
BackButton:=TButton.Create(Self);
BackButton.Parent:=Self;
BackButton.OnClick:=BackClick;
BackCaption:='< &Back';
BackButton.Width:=75;
BackButton.Height:=23;
BackButton.Enabled:=False;
// Next button
NextButton:=TButton.Create(Self);
NextButton.Parent:=Self;
NextButton.OnClick:=NextClick;
NextCaption:='&Next >';
NextButton.Width:=75;
NextButton.Height:=23;
// End button
EndButton:=TButton.Create(Self);
EndButton.Parent:=Self;
EndButton.OnClick:=EndClick;
AbortCaption:='&Cancel';
EndButton.Width:=75;
EndButton.Height:=23;
ReadyCaption:='&Finish';
// Help button
HelpButton:=TButton.Create(Self);
HelpButton.Parent:=Self;
HelpButton.OnClick:=HelpClick;
HelpCaption:='&Help';
HelpButton.Width:=75;
HelpButton.Height:=23;
End;
//
// TDelphiWizard: Destroy
//
Destructor TDelphiWizard.Destroy;
Begin
// Destroy added components
BackButton.Free;
NextButton.Free;
EndButton.Free;
HelpButton.Free;
// Default destroy procedure
Inherited Destroy;
End;
//
// TDelphiWizard: Paint
//
Procedure TDelphiWizard.Paint;
Begin
// Default paint procedure
Inherited Paint;
// Bevel
With Canvas do begin
Pen.Color:=clBtnShadow;
MoveTo(9,Self.Height-43);
LineTo(Self.Width-9,Self.Height-43);
Pen.Color:=clBtnhighlight;
MoveTo(9,Self.Height-42);
LineTo(Self.Width-9,Self.Height-42);
End;
// Back button
BackButton.Top:=Self.Height-31;
BackButton.Left:=Self.Width-243;
// Next button
NextButton.Top:=Self.Height-31;
NextButton.Left:=Self.Width-168;
// End button
EndButton.Top:=Self.Height-31;
EndButton.Left:=Self.Width-83;
// Help button
HelpButton.Top:=Self.Height-31;
HelpButton.Left:=Self.Width-327;
If EnableHelp then
HelpButton.Visible:=True
Else
HelpButton.Visible:=False;
// Check for notebook
If Not Assigned(FNoteBook) then begin
BackButton.Enabled:=False;
NextButton.Enabled:=False;
EndButton.Caption:=FReadyCaption;
End;
End;
//
// TDelphiWizard: SetNoteBook
//
Procedure TDelphiWizard.SetNoteBook(Value: TNoteBook);
Begin
FNoteBook:=Value;
FNoteBook.PageIndex:=0;
If FNoteBook.Pages.Count=1 then begin
BackButton.Enabled:=False;
NextButton.Enabled:=False;
End;
If (FNoteBook.Pages.Count>1) then begin
BackButton.Enabled:=False;
NextButton.Enabled:=True;
End;
EndButton.Enabled:=True;
End;
//
// TDelphiWizard: SetBackCaption
//
Procedure TDelphiWizard.SetBackCaption(Caption: String);
Begin
FBackCaption:=Caption;
BackButton.Caption:=Caption;
Invalidate;
End;
//
// TDelphiWizard: SetBackCaption
//
Procedure TDelphiWizard.SetNextCaption(Caption: String);
Begin
FNextCaption:=Caption;
NextButton.Caption:=Caption;
Invalidate;
End;
//
// TDelphiWizard: SetAbortCaption
//
Procedure TDelphiWizard.SetAbortCaption(Caption: String);
Begin
FAbortCaption:=Caption;
EndButton.Caption:=Caption;
Invalidate;
End;
//
// TDelphiWizard: SetFinishCaption
//
Procedure TDelphiWizard.SetReadyCaption(Caption: String);
Begin
FReadyCaption:=Caption;
End;
//
// TDelphiWizard: SetHelpCaption
//
Procedure TDelphiWizard.SetHelpCaption(Caption: String);
Begin
FHelpCaption:=Caption;
HelpButton.Caption:=Caption;
Invalidate;
End;
//
// TDelphiWizard: BackClick
//
Procedure TDelphiWizard.BackClick(Sender: TObject);
Var
p: Integer;
Begin
If Assigned(FNoteBook) then begin
p:=FNoteBook.PageIndex;
If p=1 then
BackButton.Enabled:=False;
If p>0 then begin
Dec(p);
FNoteBook.PageIndex:=p;
NextButton.Enabled:=True;
End;
FPageName:=FNoteBook.ActivePage;
EndButton.Caption:=FAbortCaption;
FReady:=False;
End;
If Assigned(FOnBackClick) then
OnBackClick(Self);
If Assigned(FOnPageChange) then
OnPageChange(Self);
End;
//
// TDelphiWizard: NextClick
//
Procedure TDelphiWizard.NextClick(Sender: TObject);
Var
p: Integer;
Begin
If Assigned(FNoteBook) then begin
p:=FNoteBook.PageIndex;
If p=FnoteBook.Pages.Count-2 then begin
NextButton.Enabled:=False;
EndButton.Caption:=FReadyCaption;
FReady:=True;
End;
If p<FNoteBook.Pages.Count-1 then begin
Inc(p);
FNoteBook.PageIndex:=p;
BackButton.Enabled:=True;
End;
FPageName:=FNoteBook.ActivePage;
End;
If Assigned(FOnNextClick) then
OnNextClick(Self);
If Assigned(FOnPageChange) then
OnPageChange(Self);
End;
//
// TDelphiWizard: EndClick
//
Procedure TDelphiWizard.EndClick(Sender: TObject);
Begin
If Assigned(FOnEndClick) then
OnEndClick(Self);
End;
//
// TDelphiWizard: HelpClick
//
Procedure TDelphiWizard.HelpClick(Sender: TObject);
Begin
If Assigned(FOnHelpClick) then
OnHelpClick(Self);
End;
//
// TDelphiWizard: Notification
//
Procedure TDelphiWizard.Notification(AComponent: TComponent; Operation: TOperation);
Begin
Inherited Notification(AComponent, Operation);
If (Operation=opRemove) and (AComponent=FNoteBook) then
FNoteBook:=nil;
End;
// ****************************************************
//
// That's it and that's that!!
// Cya all l8er guys with more nice components!
//
// m.nieuwhof@hs-ipabo.edu or alfons@xs4all.nl
//
// ****************************************************
// The
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -