home *** CD-ROM | disk | FTP | other *** search
- unit LibTestForm;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- DsgnIntf, LibIntf, StdCtrls, ExtCtrls, Tabs, Menus;
-
- type
- TLibExTest = class(TForm)
- TabSet1: TTabSet;
- Notebook1: TNotebook;
- GroupBox1: TGroupBox;
- Label1: TLabel;
- BaseReg: TEdit;
- GroupBox5: TGroupBox;
- ComboBox1: TComboBox;
- Image2: TImage;
- cbLockState: TCheckBox;
- Label5: TLabel;
- PathAndBaseName: TLabel;
- Label7: TLabel;
- AppHandle: TLabel;
- Label8: TLabel;
- IDETime: TLabel;
- Label9: TLabel;
- WinSize: TLabel;
- Label4: TLabel;
- Image1: TImage;
- GroupBox4: TGroupBox;
- Label2: TLabel;
- HelpClassName: TEdit;
- ClassHelpOK: TButton;
- GroupBox3: TGroupBox;
- ComboBox2: TComboBox;
- Label10: TLabel;
- Button1: TButton;
- GroupBox6: TGroupBox;
- SelectionType: TLabel;
- SelectionName: TLabel;
- FirstSelectionType: TLabel;
- SelectedList: TListBox;
- SetLockState: TCheckBox;
- SelectAll: TButton;
- DeleteAll: TButton;
- PropertyList: TListBox;
- EventList: TListBox;
- Label11: TLabel;
- Label12: TLabel;
- Button2: TButton;
- CompCount: TLabel;
- FileSystem: TLabel;
- FormName: TLabel;
- Show: TButton;
- ScrollBox1: TScrollBox;
- Image3: TImage;
- Ancestor: TLabel;
- FirstCompName: TLabel;
- Hide: TButton;
- NewName: TButton;
- TabCompCount: TLabel;
- FirstNVComp: TLabel;
- GroupBox2: TGroupBox;
- CIName: TLabel;
- CIEventCount: TLabel;
- EventCombo: TComboBox;
- Label3: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure HelpClassNameChange(Sender: TObject);
- procedure ClassHelpOKClick(Sender: TObject);
- procedure FormPaint(Sender: TObject);
- procedure TabSet1Change(Sender: TObject; NewTab: Integer;
- var AllowChange: Boolean);
- procedure ComboBox1Change(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure SetLockStateClick(Sender: TObject);
- procedure SelectAllClick(Sender: TObject);
- procedure DeleteAllClick(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure HideClick(Sender: TObject);
- procedure ShowClick(Sender: TObject);
- procedure NewNameClick(Sender: TObject);
- private
- { Private declarations }
- procedure GetPropertiesProc (Prop: TIProperty);
- procedure GetEventsProc (Prop: TIProperty);
- function InitFormDesignerPage: Boolean;
- public
- { Public declarations }
- end;
-
- implementation
-
- {$R *.DFM}
-
- procedure TLibExTest.FormCreate(Sender: TObject);
- begin
- TabSet1.Tabs := NoteBook1.Pages;
- ComboBox1.ItemIndex := 0;
- ComboBox2.ItemIndex := 0;
- ComboBox1Change (Self);
- end;
-
- procedure TLibExTest.HelpClassNameChange(Sender: TObject);
- begin
- ClassHelpOK.Enabled := HelpClassName.Text <> '';
- end;
-
- procedure TLibExTest.ClassHelpOKClick(Sender: TObject);
- begin
- DelphiIDE.ShowClassHelp (HelpClassName.Text);
- end;
-
- procedure TLibExTest.FormPaint(Sender: TObject);
- var
- Item: TIPaletteItem;
- begin
- with DelphiIDE do
- if GetToolSelected then begin
- Label4.Visible := True;
- Image1.Visible := True;
- Item := GetCurCompClass;
- try
- Item.Paint (Image1.Canvas, 0, 0);
- finally
- Item.Free;
- end;
- end
- else begin
- Label4.Visible := False;
- Image1.Visible := False;
- end;
- end;
-
- procedure TLibExTest.TabSet1Change (Sender: TObject; NewTab: Integer;
- var AllowChange: Boolean);
- var
- r: TRect;
- Idx: Integer;
- Selection: TComponentList;
- begin
- { Case out on the active page name }
- if NoteBook1.Pages [NewTab] = 'Form Designer' then AllowChange := InitFormDesignerPage;
- if not AllowChange then Exit else NoteBook1.PageIndex := NewTab;
-
- if NoteBook1.Pages [NewTab] = 'Miscellaneous' then with DelphiIDE do begin
- BaseReg.Text := GetBaseRegKey;
- cbLockState.Checked := LockState;
- PathAndBaseName.Caption := GetPathAndBaseExeName;
- AppHandle.Caption := '$' + IntToHex (GetAppHandle, 8);
- IDETime.Caption := '$' + IntToHex (GetCurTime, 8);
- r := GetMainWindowSize;
- WinSize.Caption := Format ('(%d,%d)-(%d,%d)', [r.Left, r.Top, r.Right, r.Bottom]);
- end;
-
- if NoteBook1.Pages [NewTab] = 'Selections' then with CompLib do begin
- if GetSelectionName <> '' then
- SelectionName.Caption := 'Name of selected component - ' + GetSelectionName
- else SelectionName.Caption := '--No component selected--';
-
- if GetSelectionType <> '' then
- SelectionType.Caption := 'Type of selected component - ' + GetSelectionType
- else SelectionType.Caption := '--No component selected--';
-
- if GetFirstSelectionType <> '' then
- FirstSelectionType.Caption := 'Type of first selected - ' + GetFirstSelectionType
- else FirstSelectionType.Caption := '--No component selected--';
-
- Selection := TComponentList.Create;
- try
- { Delphi 3 Bug - only call GetSelection if there is a selection }
- if GetFirstSelectionType <> '' then GetSelection (Selection);
-
- SelectedList.Clear;
- if Selection.Count = 0 then SelectedList.Items.Add ('---no selection---') else
- for Idx := 0 to Selection.Count - 1 do
- with Selection [Idx] as TControl do
- SelectedList.Items.Add (Format ('%s (%s)', [Name, ClassName]));
-
- finally
- Selection.Free;
- end;
-
- Self.SetLockState.Checked := DelphiIDE.LockState;
- end;
-
- if NoteBook1.Pages [NewTab] = 'More Selection Info' then with CompLib do begin
- PropertyList.Clear;
- EventList.Clear;
- GetProperties (pkProperties, GetPropertiesProc);
- GetProperties (pkEvents, GetEventsProc);
- end;
- end;
-
- procedure TLibExTest.ComboBox1Change(Sender: TObject);
- var
- Item: TIPaletteItem;
- Cls: TComponentClass;
- begin
- with DelphiIDE do begin
- case ComboBox1.ItemIndex of
- 0: Cls := TMainMenu;
- 1: Cls := TPopupMenu;
- 2: Cls := TLabel;
- 3: Cls := TEdit;
- 4: Cls := TMemo;
- 5: Cls := TButton;
- 6: Cls := TCheckBox;
- 7: Cls := TRadioButton;
- 8: Cls := TListBox;
- 9: Cls := TComboBox;
- 10: Cls := TScrollBar;
- 11: Cls := TGroupBox;
- 12: Cls := TRadioGroup;
- 13: Cls := TPanel;
- else Cls := Nil;
- end;
-
- if Cls = Nil then Image2.Visible := False else begin
- Item := GetPaletteItem (Cls);
- try
- Item.Paint (Image2.Canvas, 0, 0);
- finally
- Item.Free;
- end;
- Image2.Visible := True;
- Image2.Invalidate;
- end;
- end;
- end;
-
- procedure TLibExTest.Button1Click (Sender: TObject);
- begin
- { This will do nothing if there's no active form }
- DelphiIDE.ExecDesignDialog (TDesignDialog (ComboBox2.ItemIndex));
- end;
-
- procedure TLibExTest.GetPropertiesProc (Prop: TIProperty);
- begin
- PropertyList.Items.Add (Prop.GetName);
- Prop.Free;
- end;
-
- procedure TLibExTest.GetEventsProc (Prop: TIProperty);
- begin
- EventList.Items.Add (Prop.GetName);
- Prop.Free;
- end;
-
- procedure TLibExTest.SetLockStateClick (Sender: TObject);
- begin
- CompLib.SetLockState (SetLockState.Checked);
- end;
-
- procedure TLibExTest.SelectAllClick (Sender: TObject);
- begin
- CompLib.EditAction (eaSelectAll);
- end;
-
- procedure TLibExTest.DeleteAllClick(Sender: TObject);
- begin
- CompLib.EditAction (eaSelectAll);
- CompLib.EditAction (eaCut);
- end;
-
- procedure TLibExTest.Button2Click(Sender: TObject);
- var
- Form: TIForm;
- module: TIModule;
- begin
- Form := CompLib.GetActiveForm;
- if Form <> Nil then begin
- module := Form.GetModule;
- if module <> Nil then Module.SwapSourceFormView;
- end;
- end;
-
- { @@@@ }
-
- function TLibExTest.InitFormDesignerPage: Boolean;
- var
- Idx: Integer;
- Str: String;
- CInfo: TICompInfo;
- ActiveForm: TIForm;
- begin
- { Assume no active form }
- Result := False;
- ActiveForm := CompLib.GetActiveForm;
- if ActiveForm = Nil then begin
- ShowMessage ('Can''t access this page without an active form');
- Exit;
- end;
-
- { OK - we've got an active form }
- Result := True;
- with ActiveForm do begin
- CompCount.Caption := Format ('Number of components on form = %d', [GetCompCount]);
- Str := GetFileSystem;
- if Str = '' then Str := '[Default]';
- FileSystem.Caption := Format ('File system = %s', [Str]);
- FormName.Caption := Format ('Name of form = %s', [GetFormName]);
- Ancestor.Caption := Format ('Name of ancestor = %s', [GetAncestorName]);
- Image3.Picture.Bitmap.Handle := GetFormImage;
- if GetCompCount > 0 then Str := GetCompName (0) else Str := '--none--';
- FirstCompName.Caption := Format ('Name of first component = %s', [Str]);
- TabCompCount.Caption := Format ('Number of TabStop Components = %d', [GetTabCompCount]);
- { Find first non-visual component, if any }
- Str := '--none--';
- for Idx := 0 to GetCompCount - 1 do
- if GetNVComp (Idx) <> Nil then begin
- Str := TComponent (GetNVComp (Idx)).Name;
- break;
- end;
-
- FirstNVComp.Caption := Format ('First non-visual component = %s', [Str]);
-
- { Do something to demonstrate the TICompInfo interface }
- GroupBox2.Visible := GetCompCount > 0;
- if GroupBox2.Visible then begin
- CInfo := GetCompInfo (0);
- try
- CIName.Caption := TComponent(CInfo.GetComponentHandle).Name;
- CIName.Caption := CIName.Caption + Format (' (%s)', [CInfo.GetClassName]);
- CIEventCount.Caption := Format ('%d Possible Event handlers', [CInfo.GetEventCount]);
- EventCombo.Items.Clear;
- for Idx := 0 to CInfo.GetEventCount - 1 do begin
- Str := CInfo.GetEventValue (Idx);
- if Str <> '' then EventCombo.Items.Add (Str);
- end;
-
- if EventCombo.Items.Count = 0 then EventCombo.Items.Add ('--none--');
- EventCombo.ItemIndex := 0;
- finally
- CInfo.Free;
- end;
- end;
- end;
- end;
-
- procedure TLibExTest.HideClick(Sender: TObject);
- begin
- CompLib.GetActiveForm.Hide;
- end;
-
- procedure TLibExTest.ShowClick(Sender: TObject);
- begin
- CompLib.GetActiveForm.Show;
- end;
-
- procedure TLibExTest.NewNameClick(Sender: TObject);
- var
- NewName: String;
- begin
- with CompLib.GetActiveForm do begin
- NewName := InputBox ('LibIntf Expert', 'Enter a new name for the form', GetFormName);
- if (NewName <> '') and (NewName <> GetFormName) then begin
- SetFormName (NewName);
- InitFormDesignerPage;
- end;
- end;
- end;
-
- end.
-
- public
- procedure Align (Affect:TAffect); { $2C }
- procedure CreateComponent (Item: TICompClass); { $30 }
- function FindCompClass (const CompName: String): String; { $34 }
- procedure GetDependentForms(Proc:TGetFormProc); { $40 }
- procedure GetFormDependencies (Proc: TGetFormProc); { $48 }
- function GetModule: TIModule; { $54 }
- function GetFormInterface: TIFormInterface; { $60 }
- function GetState: TFormState; { $70 }
- procedure GoDormant;
- procedure RemoveDependentLinks;
- procedure Scale(Factor:integer); { $98 }
- procedure SetSelection(const Name:string);
- procedure ShowAs(ShowState:TShowState);
- procedure Size(Affect:TSizeAffect; Value:integer); { $B8 }
- end;
-
-
-
-
-
-
-