📄 objectinspec.~pas
字号:
begin
{ Editor:= TPropertyEditor(PropertyList.Objects[I]);
if Editor <> nil then
begin
fPropertyAttr:= Editor.GetAttributes;
if (paSubProperties in PropAttrs) then
begin
ListBox.Items.Add(Format('+%-20s',[Info^.Name])+ Prop);
end
else
ListBox.Items.Add(Format('%-20s',[Info^.Name])+ Prop);
end;}
if Info^.PropType^.Kind in [tkClass] then
begin
if IsA(Info^.PropType^, 'TCOMPONENT') then
ListBox.Items.Add(Format('%-20s',[Info^.Name])+ Prop)
else ListBox.Items.Add(Format('+%-20s',[Info^.Name])+ Prop);
end
else if Info^.PropType^.Kind in [tkSet] then
ListBox.Items.Add(Format('+%-20s',[Info^.Name])+ Prop)
else if Info^.PropType^.Kind in [tkMethod] then
ListBox.Items.Add(Format('%-20s',[Info^.Name])+ Prop)
else ListBox.Items.Add(Format('%-20s',[Info^.Name])+ Prop);
end;
begin
EventCount:=0;
Count := GetPropList(Info,tkProperties,nil); // get property count
Count1:= GetPropList(Info,tkMethods,nil); // get event count
GetMem(PropList,Count*SizeOf(PPropInfo));
GetMem(PropList1,Count1*SizeOf(PPropInfo));
try
GetPropList(Info,tkProperties,PropList);
for I:=0 to Count-1 do
begin
Prop:= WritePropInfo(PropList^[I],I,Sender);
AddPropItem(PropertyBox, PropList^[I]);
end;
GetPropList(Info,tkMethods,PropList1);
for I:=0 to Count1-1 do
begin
Prop:= WritePropInfo(PropList1^[I],I,Sender);
AddPropItem(EventBox, PropList1^[I]);
end;
finally
FreeMem(PropList,Count*SizeOf(PPropInfo));
FreeMem(PropList1,Count1*SizeOf(PPropInfo));
end;
end;
procedure TObjectInspector.ClearProperties;
begin
PropertyBox.Clear;
EventBox.Clear;
PropertyList.Clear;
end;
procedure TObjectInspector.GetPropertyInfo(Sender: TObject);
// Get property, event list and value for selected component
var
Info:PTypeInfo;
Data:PTypeData;
begin
Info:= Sender.ClassInfo;
if Info = nil then Exit;
Data:= GetTypeData(Info);
GetProperties(Sender as TComponent);
WritePropertyInfo(Info,Data,Sender);
end;
{ The user has chosen a property, so get the editor,
and initialize the property editor fields. }
procedure TObjectInspector.SetEditor(Editor: TPropertyEditor);
var
PTypeName, ClassName:string;
begin
fPropertyEditor:= Editor;
if Editor= nil then Exit;
Editor.Activate;
fPropertyAttr:= Editor.GetAttributes;
if (paDialog in PropAttrs) then SetEditBounds(Browse)
else SetEditBounds(nil);
cbValue.Clear;
PTypeName:= Editor.GetPropType.Name;
ClassName:= Editor.ClassName;
//加己捞 捞亥飘啊 酒聪绊 格废阑 啊瘤绊 乐栏搁 加己蔼狼 格废阑 焊咯霖促.
if ((paValueList in PropAttrs) and (ClassName<>'TMethodProperty')) then
begin
Editor.GetValues(GetValueProc);
SetEditBounds(cbValue);
end
else if (ClassName ='TMethodProperty') then
begin
// Editor.GetValues(GetEventValueProc);
cbEvent.Items.Assign(ProxyDesigner.Methods);
SetEditBounds(cbEvent);
end
else if ClassName='TFontProperty' then SetEditBounds(Browse)
else if (PTypeName = 'TBitmap') then SetEditBounds(Browse)
else if (PTypeName = 'TIcon') then SetEditBounds(Browse)
else if (PTypeName = 'TTabSheet') then GetPrpoertyItemList('TTabSheet', False)
else if (PTypeName = 'TWinControl') then GetPrpoertyItemList('TWinControl', True)
else if (GetPropertyName = 'DatabaseName') then GetDatabaseNameList
else if (GetPropertyName = 'TableName') then GetTableNameList
else SetEditBounds(edProperty);
StatusBar1.SimpleText:= Editor.GetPropType.Name+' : '+ClassName;
// 加己捞 捞亥飘啊 酒聪搁 加己蔼阑 盎脚茄促.
if (ClassName<>'TMethodProperty') then UpdateValue;
if edProperty.Visible then edProperty.Text:= Editor.GetValue
else if cbValue.Visible then SetcbValueIndex(Editor.GetValue)
// else if cbEvent.Visible then cbEvent.Text:= Editor.GetValue;
end;
{ Callback for getting a subproperty editor. }
procedure TObjectInspector.GetPropEditor(Editor: TPropertyEditor);
begin
Editor.Initialize;
PropertyList.AddObject(Editor.GetName, Editor);
end;
// Font客 鞍捞 SubProperties甫 爱绰 加己狼 窍困 加己阑
// 焊咯林绰 Callback 橇肺矫历
procedure TObjectInspector.GetSubPropEditor(Editor: TPropertyEditor);
var
Prop:string;
begin
Editor.Initialize;
Prop:= Format(' %-18s%-s',[Editor.GetName, Editor.GetValue]);
PropertyList.InsertObject(PropertyBox.ItemIndex + 1, Editor.GetName, Editor);
PropertyBox.Items.Insert(PropertyBox.ItemIndex + 1, Prop);
end;
procedure TObjectInspector.GetEventEditor(Editor: TPropertyEditor);
begin
EventList.AddObject(Editor.GetName, Editor);
end;
procedure TObjectInspector.GetProperties(Component: TComponent);
// 哪欺惩飘啊 啊瘤绊 乐绰 加己苞 弊 蔼阑 焊咯霖促.
var
CompList: TComponentList;
Comp1List: TComponentList;
begin
PropertyList.BeginUpdate;
EventList.BeginUpdate;
ClearProperties;
CompList := TComponentList.Create;
Comp1List:= TComponentList.Create;
try
CompList.Add(Component);
Comp1List.Add(Component);
// 哪欺惩飘Component俊 措茄 加己 祈笼扁甫 积己茄促.(加己俊 措茄 祈笼扁)
GetComponentProperties(CompList, tkProperties,ProxyDesigner , GetPropEditor);
// 哪欺惩飘俊 措茄 加己(捞亥飘)俊 措茄 加己 祈笼扁甫 积己茄促.(葛电 捞亥飘)
GetComponentProperties(Comp1List, tkMethods, ProxyDesigner, GetEventEditor);
finally
CompList.Free;
Comp1List.Free;
end;
PropertyList.EndUpdate;
EventList.EndUpdate;
end;
{ Initialize the property editor form. }
procedure TObjectInspector.Initialize(Component: TComponent);
begin
{$IFDEF DELPHI3}
Designer := ProxyDesigner;
{$ENDIF}
fComponent := Component;
end;
procedure TObjectInspector.FormCreate(Sender: TObject);
begin
propedit.Register; // 葛电 加己 祈笼扁甫 殿废茄促.
PropertyList:= TStringList.Create;
EventList := TStringList.Create;
Left:=0;
PageControl1.ActivePage:=TabProperty;
ComponentList.Items.Add('Form1:TForm1');
end;
procedure TObjectInspector.FormResize(Sender: TObject);
// 汽狼 农扁啊 官拆 版快 阿 牧飘费狼 承捞甫 犁炼沥茄促.
begin
ComponentList.Width:=Width-10;
EditRect.Right := PropertyBox.ItemRect(PropertyBox.ItemIndex).Right;
if Browse.Visible then SetEditBounds(Browse)
else if edProperty.Visible then SetEditBounds(edProperty)
else if cbEvent.Visible then SetEditBounds(cbEvent)
else if cbValue.Visible then SetEditBounds(cbValue);
end;
function TObjectInspector.ExtractComponentName(const S:string):string;
// 坷宏璃飘 牢胶棋飘狼 哪欺惩飘 格废俊辑 哪欺惩飘 捞抚父 眠免茄促.
var
SepaPos:integer;
begin
Result:='';
SepaPos:=Pos(':',S);
if SepaPos>1 then Result:= Copy(S,1,SepaPos-1);
end;
function TObjectInspector.ExtractComponentType(const S:string):string;
// 坷宏璃飘 牢胶棋飘狼 哪欺惩飘 格废俊辑 哪欺惩飘 type父 眠免茄促.
var
SepaPos:integer;
begin
Result:='';
if S = '' then Exit;
SepaPos:=Pos(':',S);
if SepaPos > 1 then Result:= Copy(S,SepaPos + 1, Length(S));
end;
function TObjectInspector.GetComponentName: string;
// 泅犁 急琶茄 哪欺惩飘狼 捞抚阑 倒妨霖促.
begin
with ComponentList do
if ItemIndex<0 then Result := ''
else Result := ExtractComponentName(Items[ItemIndex]);
end;
// Object Inspector俊辑 急琶茄 哪欺惩飘甫 倒妨霖促.
// 厚矫阿利 哪欺惩飘甫 急琶茄 版快俊绰 Wrapper俊 WrapperControl甫 且寸茄促.
function TObjectInspector.GetComponent(var Wrapper:TComponent): TComponent;
var
WrapperName,ComponentName:string;
Component:TComponent;
begin
Result:= nil;
if ProxyDesigner = nil then Exit;
Wrapper:= nil;
ComponentName:= GetComponentName;
WrapperName:= 'Wrapper'+ComponentName;
if ComponentName = ProxyDesigner.Form.Name then
Result := ProxyDesigner.Form
else begin
Component:= ProxyDesigner.Form.FindComponent(WrapperName);
if Component<>nil then Wrapper:= Component;
Result := ProxyDesigner.Form.FindComponent(ComponentName);
end;
end;
// Display component information at object inspector
// Wrapper: wrapper control for non visual component (wrapper =nil when visual component)
procedure TObjectInspector.DisplayProperty(Wrapper,Component:TComponent);
var
Name:string;
Control:TComponent;
begin
if ProxyDesigner = nil then Exit;
if Component <> nil then
begin
SetEditBounds(nil); // hide object inspecotor controls for editing
GetPropertyInfo(TObject(Component));
if Wrapper <> nil then ProxyDesigner.SelectComponent(Wrapper)
else ProxyDesigner.SelectComponent(Component);
if Component is TForm then Name:= ProxyDesigner.Form.ClassName
else Name:= Component.ClassName;
SelectComponent:= Component;
if Component is TWrapperControl then
begin
Control:= (Component as TWrapperControl).Component;
Name:= Control.ClassName;
ComponentList.ItemIndex:= GetItemIndex(Control);
end
else ComponentList.ItemIndex:= GetItemIndex(Component);
end;
end;
procedure TObjectInspector.EditorProperty;
begin
if (PropertyEditor <> nil) then
begin
PropertyEditor.Edit;
UpdateValue;
end;
SetPropertyValueName(PropertyEditor.GetValue);
end;
procedure TObjectInspector.PropSetValue(const Value: string);
// 加己狼 蔼阑 Value肺 汲沥茄促.
begin
if PropertyEditor <> nil then
begin
PropertyEditor.SetValue(Value);
UpdateValue;
end;
end;
procedure TObjectInspector.UpdateValue;
begin
end;
function TObjectInspector.GetPropValue(Info:PPropInfo):TStringList;
// 加己捞 啊瘤绰 凯芭屈 蔼肚绰 笼钦阑 倒妨霖促.(巩磊凯)
var
Data:PTypeData;
I,MinVal,MaxVal: Integer;
ValueList: TStringList;
TypeInfo1 :PTypeInfo;
begin
ValueList:= TStringList.Create;
Data:= GetTypeData(Info^.PropType^);
case Info^.PropType^.Kind of
tkEnumeration:
begin
for I:= Data.MinValue to Data.MaxValue do
ValueList.Add(GetEnumName(Info^.PropType^,I));
end;
tkSet:
begin
Data := GetTypeData(Info^.PropType^);
TypeInfo1:= Data^.CompType^;
Data := GetTypeData(TypeInfo1);
MinVal := Data^.MinValue;
MaxVal := Data^.MaxValue;
for I:= MinVal to MaxVal do
ValueList.Add(GetEnumName(TypeInfo1,I));
end;
end;
Result:= ValueList;
end;
procedure TObjectInspector.SetEditBounds(AControl : TWinControl);
// 加己狼 type俊 蝶扼 加己蔼阑 涝仿且 牧飘费阑 搬沥茄促.
var
Index: Integer;
begin
// 加己捞 凯芭屈 肚绰 笼钦屈牢 版快, 加己蔼 霓焊 冠胶甫 加己 困摹俊 嘎眠绊,
// 弊犯瘤 臼栏搁 霓焊 冠胶甫 焊捞瘤 臼霸 茄促.
if AControl <> nil then with AControl do
begin
cbValue.Visible := False;
Browse.Visible := False;
edProperty.Visible:= False;
cbEvent.Visible := False;
Visible := True;
SetFocus;
if AControl = cbValue then
begin
// cbValue.SetBounds(EditRect.Left+1,EditRect.Top,
// EditRect.Right-EditRect.Left+3,EditRect.Bottom - EditRect.Top);
Index:= cbValue.Items.IndexOf(GetPropertyValueName);
if Index<>-1 then cbValue.ItemIndex:= Index
else cbValue.Text:= GetPropertyValueName;
end
{ else if AControl = edProperty then
begin
edProperty.SetBounds(EditRect.Left+1,EditRect.Top + 1,
EditRect.Right-EditRect.Left+3,EditRect.Bottom - EditRect.Top);
end
else if AControl = Browse then
begin
Browse.SetBounds(EditRect.Right-Browse.Width, EditRect.Top+1, Browse.Width, PropertyBox.ItemHeight - 2);
end}
else if AControl = cbEvent then
begin
cbEvent.SetBounds(EditRect.Left+1,EditRect.Top,
EditRect.Right-EditRect.Left+3,EditRect.Bottom - EditRect.Top);
cbEvent.Width:= EventBox.ClientWidth - HalfWay;
cbEvent.Text:= Copy(EventBox.Items[EventBox.ItemIndex], 21, 255);
end;
end
else
begin
cbValue.Visible := False;
Browse.Visible := False;
edProperty.Visible:= False;
cbEvent.Visible := False;
end;
end;
procedure TObjectInspector.ComboValueChange(Sender: TObject);
begin
PropSetValue(cbValue.Text);
end;
procedure TObjectInspector.StringGrid2DblClick(Sender: TObject);
// 捞亥飘俊 措茄 家胶 内靛甫 积己茄促.
var
EventName: string;
EventHandler:string;
begin
EventName:= ExtractComponentName(ComponentList.text);
EventHandler:= EventName;
// 捞亥飘狼 颇府固磐甫 炼荤茄促.
EventName:= EventName+'('+WriteMethodData(GetTypeData(PropertyEditor.GetPropType))+');';
// 捞亥飘 勤甸矾甫 累己窍瘤 臼疽栏搁 捞亥飘 勤甸矾甫 累己窍绊, 内靛 祈笼扁甫 劝己拳茄促.
end;
{ Get a value from the list of string values. }
procedure TObjectInspector.GetValueProc(const Value: string);
begin
cbValue.Items.Add(Value);
end;
procedure TObjectInspector.GetEventValueProc(const Value: string);
begin
cbEvent.Items.Add(Value);
end;
procedure TObjectInspector.PropertyBoxDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
sr,dr: TRect;
PropName,PropValue:string;
begin
with (Control as TListBox).Canvas do
begin
Brush.Color := PropertyBox.Color; {Won't use Windows Selected color.}
FillRect(Rect);
// 啊肺急阑 弊覆
if (odSelected in State) then Pen.Color := clBtnHighLight else {for 3D look}
Pen.Color := clBtnShadow;
Pen.Mode := pmCopy;
Pen.Width := 1;
Pen.Style := psSolid;
MoveTo(Rect.Left, Rect.Bottom-1);
LineTo(Rect.Right, Rect.Bottom-1);
// Item狼 吝埃俊 靛贰弊甫 困茄 荐流急阑 弊覆
if (odFocused in State) then
begin
Pen.Color := clBtnHighLight;
MoveTo(HalfWay + 2, Rect.Top+1);
LineTo(Halfway + 2, Rect.Bottom);
Pen.Color := clBtnShadow;
MoveTo(Halfway+1, Rect.Top+2);
LineTo(Halfway+1, Rect.Bottom);
MoveTo(Rect.Right, Rect.Top);
LineTo(Rect.Left, Rect.Top);
LineTo(Rect.Left, Rect.Bottom);
Pen.Color := clBlack;
MoveTo(Rect.Right-1, Rect.Top+1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -