1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
unit MainUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, TypInfo, Forms, Controls, StdCtrls,
ObjectInspector, PropEdits, PropEditUtils, GraphPropEdits;
type
{ TMyComponent }
TMyComponent = class(TComponent)
private
FAnInteger: integer;
FWideStr: widestring;
FUnicodeStr: unicodestring;
FAnsiStr: ansistring;
procedure SetAnInteger(const AValue: integer);
public
published
property AnInteger: integer read FAnInteger write SetAnInteger;
property WideStr: widestring read FWideStr write FWideStr;
property UnicodeStr: unicodestring read FUnicodeStr write FUnicodeStr;
property AnsiStr: ansistring read FAnsiStr write FAnsiStr;
end;
{ TForm1 }
TForm1 = class(TForm)
PropGridGroupbox: TGroupBox;
SetCompAsOIRootButton: TButton;
SetOIRootFormButton: TButton;
OIGroupbox: TGroupBox;
PropertyGrid: TOIPropertyGrid;
procedure Form1Create(Sender: TObject);
procedure Form1Destroy(Sender: TObject);
procedure SetOIRootFormButtonClick(Sender: TObject);
procedure SetCompAsOIRootButtonClick(Sender: TObject);
private
procedure SetObjectInspectorRoot(AComponent: TComponent);
protected
function GetOwner: TPersistent; override;
public
TheObjectInspector: TObjectInspectorDlg;
ThePropertyEditorHook: TPropertyEditorHook;
ARootComponent: TMyComponent;
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Form1Create(Sender: TObject);
begin
// create the PropertyEditorHook (the interface to the properties)
ThePropertyEditorHook:=TPropertyEditorHook.Create(nil);
// create the ObjectInspector
TheObjectInspector:=TObjectInspectorDlg.Create(Application);
TheObjectInspector.PropertyEditorHook:=ThePropertyEditorHook;
TheObjectInspector.SetBounds(10,10,240,500);
// create a second Root component for demonstration
ARootComponent:=TMyComponent.Create(nil);
// create the PropertyGrid
PropertyGrid:=TOIPropertyGrid.CreateWithParams(Self,ThePropertyEditorHook,
AllTypeKinds,25);
with PropertyGrid do begin
Name:='PropertyGrid';
Parent:=PropGridGroupbox;
Align:=alClient;
end;
// select the Form1 in the ObjectInspector
SetObjectInspectorRoot(Self);
TheObjectInspector.Show; // For some reason this is not shown otherwise
end;
procedure TForm1.Form1Destroy(Sender: TObject);
begin
// TheObjectInspector is owned by Application and therefore destroyed automatically
ThePropertyEditorHook.Free;
ARootComponent.Free;
end;
procedure TForm1.SetOIRootFormButtonClick(Sender: TObject);
begin
SetObjectInspectorRoot(Self);
end;
procedure TForm1.SetCompAsOIRootButtonClick(Sender: TObject);
begin
SetObjectInspectorRoot(ARootComponent);
end;
procedure TForm1.SetObjectInspectorRoot(AComponent: TComponent);
var
Selection: TPersistentSelectionList;
begin
ThePropertyEditorHook.LookupRoot:=AComponent;
Selection:=TPersistentSelectionList.Create;
Selection.Add(AComponent);
TheObjectInspector.Selection:=Selection;
PropertyGrid.Selection:=Selection;
Selection.Free;
end;
function TForm1.GetOwner: TPersistent;
begin
// this form is the LookupRoot => GetOwner must be nil
// see GetLookupRootForComponent
Result:=nil;
end;
{ TMyComponent }
procedure TMyComponent.SetAnInteger(const AValue: integer);
begin
if FAnInteger=AValue then exit;
FAnInteger:=AValue;
end;
{$R *.lfm}
end.
|