Marco Cantù 1998, Mastering Delphi 4
Package: MD4DESPK.DPK
Package Structure
MD4WIZARD.PAS
unit Md4Wizard;
interface
uses
ExptIntf, Windows;
type
TMd4Expert = class (TIExpert)
public
function GetStyle: TExpertStyle; override;
function GetName: string; override;
function GetAuthor: string; override;
function GetComment: string; override;
function GetPage: string; override;
function GetGlyph: HICON; override;
function GetState: TExpertState; override;
function GetIDString: string; override;
function GetMenuText: string; override;
procedure Execute; override;
end;
procedure Register;
implementation
uses
Dialogs, ToolIntf, SysUtils;
function TMd4Expert.GetStyle: TExpertStyle;
begin
// show up in the Help menu
Result := esStandard;
end;
function TMd4Expert.GetName: String;
begin
// official name
Result := 'MDWizard'
end;
function TMd4Expert.GetAuthor: string;
begin
Result := 'Marco Cantù';
end;
function TMd4Expert.GetComment: String;
begin
Result := 'Mastering Delphi Wizard';
end;
function TMd4Expert.GetPage: string;
begin
Result := '';
end;
function TMd4Expert.GetGlyph: HICON;
begin
Result := 0;
end;
function TMd4Expert.GetState: TExpertState;
begin
// always enabled, never checked
Result := [esEnabled];
end;
function TMd4Expert.GetIDString: String;
begin
// must be unique
Result := 'MarcoCantu.MDWizard'
end;
function TMd4Expert.GetMenuText: String;
begin
// the text of the menu item
Result := '&Mastering Delphi Wizard...'
end;
procedure TMd4Expert.Execute;
begin
// the actual code, showing some internal information
MessageDlg (
'Mastering Delphi Wizard'#13#13 +
'Current project: '#13 +
ToolServices.GetProjectName + #13 +
'(units: ' + IntToStr (ToolServices.GetUnitCount) +
', forms: ' + IntToStr (ToolServices.GetFormCount) + ')'#13#13 +
'Current file: '#13 +
ToolServices.GetCurrentFile + #13#13+
'Delphi information in the registry is under:'#13 +
ToolServices.GetBaseRegistryKey,
mtInformation, [mbOK], 0);
end;
procedure Register;
begin
RegisterLibraryExpert (TMd4Expert.Create);
end;
end.
MD4PROPEDIT.PAS
unit Md4PropEdit;
interface
uses
DsgnIntf;
type
TMd4IntListProperty = class (TStringProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;
procedure Register;
implementation
uses
SysUtils, Md4IlpeForm, Md4TabList, Forms, Controls;
function TMd4IntListProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paReadOnly];
end;
procedure TMd4IntListProperty.Edit;
var
PEForm: TIntListPEForm;
Tabs: TMd4TabbedList;
I: Integer;
begin
PEForm := TIntListPEForm.Create (Application);
try
Tabs := GetComponent (0) as TMd4TabbedList;
for I := Low (TMd4TabsArray) to High (TMd4TabsArray) do
PEForm.Memo1.Lines.Add (IntToStr (Tabs.TabStops [I]));
if PEForm.ShowModal = mrOK then
begin
for I := Low (TMd4TabsArray) to High (TMd4TabsArray) do
Tabs.TabStops [I] := StrToIntDef (PEForm.Memo1.Lines [I], 0);
Designer.Modified;
end;
finally
PEForm.Free;
end;
end;
procedure Register;
begin
RegisterPropertyEditor (TypeInfo (string),
TMd4TabbedList, 'TabsString', TMd4IntListProperty);
end;
end.
MD4ILPEFORM.PAS
unit Md4IlpeForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;
type
TIntListPEForm = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Memo1: TMemo;
BitBtn3: TBitBtn;
procedure BitBtn3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{var
IntListPEForm: TIntListPEForm;}
implementation
{$R *.DFM}
procedure TIntListPEForm.BitBtn3Click(Sender: TObject);
var
I: Integer;
begin
for I := 0 to 9 do
Memo1.Lines [I] := IntToStr (I * 100);
end;
end.
MD4COMPEDIT.PAS
unit Md4CompEdit;
interface
uses
DsgnIntf;
type
TMd4TabListEditor = class (TComponentEditor)
function GetVerbCount: Integer; override;
function GetVerb(Index: Integer): string; override;
procedure ExecuteVerb(Index: Integer); override;
procedure Edit; override;
end;
procedure Register;
implementation
uses
SysUtils, Dialogs, Md4TabList, StdCtrls;
function TMd4TabListEditor.GetVerbCount: Integer;
begin
Result := 3;
end;
function TMd4TabListEditor.GetVerb (Index: Integer): string;
begin
case Index of
0: Result := 'Md4TabbedList (©Cantù)';
1: Result := '&About this component...';
2: Result := '&Reset Tabs';
end;
end;
procedure TMd4TabListEditor.ExecuteVerb (Index: Integer);
var
I: Integer;
begin
case Index of
0..1: MessageDlg (
'This is a simple component editor'#13 +
'built by Marco Cantù'#13 +
'for the book "Mastering Delphi 4"',
mtInformation, [mbOK], 0);
2: begin
with Component as TMd4TabbedList do
for I := Low (TMd4TabsArray) to High (TMd4TabsArray) do
TabStops [I] := I * 100;
// data has changed
Designer.Modified;
end;
end;
end;
procedure TMd4TabListEditor.Edit;
begin
// produce a beep and show the about box
Beep;
ExecuteVerb (0);
end;
procedure Register;
begin
RegisterComponentEditor (
TMd4TabbedList, TMd4TabListEditor);
end;
end.
Copyright Marco Cantù 1998