📄 utype.pas
字号:
index by 1, so that index 0 can be interpreted as a nil pointer. Thus, the
first method in the list has index 1. After creating the method, show it
to the user. }
function TProxyDesigner.CreateMethod(const Name: string; TypeData: PTypeData): TMethod;
begin
if not MethodExists(Name) then
Methods.AddObject(Name, TObject(TypeData));
Result.Data := nil;
Result.Code := Pointer(Methods.IndexOf(Name) + 1);
ShowMethod(Name);
end;
{ Call Proc for each method whose type matches TypeData. }
procedure TProxyDesigner.GetMethods(TypeData: PTypeData; Proc: TGetStrProc);
var
I: Integer;
begin
with Methods do
for I := 0 to Count-1 do
if Objects[I] = TObject(TypeData) then
Proc(Strings[I]);
end;
{ Get the name of a method whose pointer is TMethod. Look up the
method name by its index in the method's Code field. Remember that
indexes are offset by one. }
function TProxyDesigner.GetMethodName(const Method: TMethod): string;
begin
if Method.Code = nil then
Result := ''
else
Result := Methods.Strings[Integer(Method.Code) - 1];
end;
{ Return whether a method exists with the given Name. }
function TProxyDesigner.MethodExists(const Name: string): Boolean;
begin
Result := Methods.IndexOf(Name) >= 0;
end;
{ Rename a method from CurName to NewName. }
procedure TProxyDesigner.RenameMethod(const CurName, NewName: string);
var
Index: Integer;
begin
Index := Methods.IndexOf(CurName);
Methods.Strings[Index] := NewName;
end;
{ Show a method to the user by highlighting it in the list box. }
procedure TProxyDesigner.ShowMethod(const Name: string);
begin
//ComponentForm.MethodList.ItemIndex := Methods.IndexOf(Name);
end;
function TProxyDesigner.GetPrivateDirectory: string;
begin
end;
{$ifndef VER80}
{ No form inheritance in the debugging designer. }
function TProxyDesigner.MethodFromAncestor(const Method: TMethod): Boolean;
begin
Result := False;
end;
{$endif}
// 哪欺惩飘甫 昏力茄 版快, 急琶且 促澜 哪欺惩飘甫 沥茄促.
procedure TProxyDesigner.FindNextControl;
var
Name:string;
Index:Integer;
begin
if TProxyForm(Form).ComponentList.Count <= 0 then begin
ObjectInspector.ComponentList.ItemIndex:=0;
ObjectInspector.ComponentListClick(self);
Exit;
end;
Name:= TProxyForm(Form).ComponentList[TProxyForm(Form).ComponentList.Count - 1];
Index:= ObjectInspector.ComponentList.Items.IndexOf(Name);
if Index <> -1 then
ObjectInspector.ComponentList.ItemIndex:= Index
else ObjectInspector.ComponentList.ItemIndex:=0;
ObjectInspector.ComponentListClick(self);
end;
// Control甫 昏力窍绊, 促澜 牧飘费阑 急琶茄促.
procedure TProxyDesigner.DeleteControl(Control: TControl;Next:Boolean);
var
Name:string;
Index:Integer;
begin
if (Control = nil) or (Control = Form) then Exit;
Name:= Control.Name + ':' + Control.ClassName;
Index:= TProxyForm(Form).ComponentList.IndexOf(Name);
if Index <> -1 then TProxyForm(Form).ComponentList.Delete(Index);
ObjectInspector.ComponentList.Items.Delete(ObjectInspector.ComponentList.Items.IndexOf(Name));
EditorForm.WriteComponentCode(Control.Name,
TComponentClass(Control.ClassType),wrDelete);
Control.Free;
if Next then FindNextControl; // 急琶且 哪欺惩飘甫 茫酒 急琶茄促.
end;
// 汽俊辑 急琶茄 哪欺惩飘甫 昏力茄促.
procedure TProxyDesigner.DeleteSelectList;
var
I:Integer;
begin
TProxyForm(Form).SelectControl:= nil;
for I:= 0 to fSelectList.Count-1 do
DeleteControl(fSelectList[I], False);
FindNextControl;
end;
procedure TProxyDesigner.SelectComponent(Instance: TPersistent);
var
I:Integer;
begin
{ Create the grab handles, so the user can move & resize. }
if not (fMultiSelected) and (fGrabHandles<>nil) then begin
for I:=fGrabList.Count-1 downto 0 do begin
TGrabHandles(fGrabList[I]).Free;
fGrabList.Delete(I);
fSelectList.Delete(I);
end;
end;
try
fGrabHandles :=TGrabHandles.Create(TControl(Instance));
fGrabList.Add(TPersistent(fGrabHandles));
fSelectList.Add(Instance);
except
on EAccessViolation do
Exit;
end;
FMainForm.SelectedComponent:=TComponent(Instance);
end;
// 橇废矫 汽俊 哪欺惩飘甫 积己茄促.
// ComponentClass: 积己且 哪欺惩飘 努贰胶
// Parent: 积己且 哪欺惩飘狼 何葛 哪欺惩飘
// Left,Top,Width,Height: 积己且 哪欺惩飘狼 困摹
function TProxyDesigner.CreateComponent(ComponentClass: TComponentClass;Parent:TComponent;
Left,Top,Width,Height:Integer):TComponent;
var
Component: TComponent;
Control :TControl;
begin
Result:=nil;
if ComponentClass=nil then Exit;
Component:=ComponentClass.Create(Form);
if Component is TControl then // 矫阿利 哪欺惩飘牢 版快
begin
Control := TControl(Component);
Control.Name:=UniqueName(ComponentClass.ClassName);
if Left>0 then Control.Left:=Left;
if Top>0 then Control.Top:=Top;
if Width>0 then Control.Width:=Width;
if Height>0 then Control.Height:=Height;
Control.Parent := TWinControl(Parent);
end
else begin // Create a wrapper control for nonvisual components.
Control := TWrapperControl.Create(Form, Component);
// Wrapper狼 捞抚篮 Wrapper+哪欺惩飘狼 捞抚栏肺 沥茄促.
Component.Name:=UniqueName(ComponentClass.ClassName);
Control.Name:='Wrapper'+Component.Name;
if Left>0 then Control.Left:=Left;
if Top>0 then Control.Top:=Top;
if Width>0 then Control.Width:=Width;
if Height>0 then Control.Height:=Height;
Control.Parent := TWinControl(Parent);
end;
// 积己茄 哪欺惩飘啊 皋技瘤甫 罐瘤 臼档废 csDesigning flag甫 True肺 汲沥茄促.
TExposeComponent(Control).SetDesigning(True);
// 积己茄 哪欺惩飘俊 措茄 内靛 累己
EditorForm.WriteComponentCode(Component.Name,ComponentClass,wrInsert);
TProxyForm(Form).SelectControl:= Control;
TProxyForm(Form).GrabHandles := fGrabHandles;
AddComponentList(Component);
// 坷宏璃飘 牢胶棋飘俊 秦寸 哪欺惩飘狼 加己苞 蔼阑 焊咯霖促.
if Control.ClassType=TWrapperControl then
ObjectInspector.DisplayProperty(Control,(Control as TWrapperControl).Component)
else ObjectInspector.DisplayProperty(nil,Control);
// 哪欺惩飘狼 迫饭飘 其捞瘤俊辑 拳混钎 滚瓢阑 急琶茄促.
if not FMainForm.ShiftKeyed then
TSpeedButton(FMainForm.PageControl1.ActivePage.Controls[0]).Down:= True;
Result:=Component;
end;
{钎霖 胆颇捞狼 盔蘑阑 荤侩窍咯 哪欺惩飘俊 措茄 蜡老茄 捞抚阑 积己茄促. 溜 <鸥涝><箭磊>
屈侥阑 荤侩窍绰单, <鸥涝>篮 哪欺惩飘狼 努贰胶 捞抚俊辑 'T'甫 猾 巴捞绊, <箭磊>绰
捞抚阑 窜老窍霸 父甸扁 困茄 沥荐捞促.}
function TProxyDesigner.UniqueName(const BaseName:string):string;
var
I:Integer;
Fmt:string;
begin
if BaseName[1] in ['t','T'] then
Fmt:=Copy(BaseName,2,255)+'%d'
else Fmt:=BaseName+'%d';
{蜡老茄 捞抚捞 唱棵 锭鳖瘤 , 啊瓷茄 箭磊甫 葛滴 矫氰茄促.}
for I:=1 to High(Integer) do begin
Result:=Format(Fmt,[I]);
if Form.FindComponent(Result)=nil then Exit;
end;
end;
// 汽俊 乐绰 哪欺惩飘狼 格废阑 炼荤茄促.
procedure TProxyDesigner.GetComponentList;
var
I:integer;
begin
ObjectInspector.ComponentList.Clear;
ObjectInspector.ComponentList.Items.Add(Form.Name+':TForm');
with Form do begin
for I:=0 to ComponentCount-1 do
if (Components[I].ClassType<>TGrabHandle) and (Components[I].ClassType<>TWrapperControl) then
ObjectInspector.ComponentList.Items.Add(Components[I].Name+':'+Components[I].ClassName)
end;
end;
// 橇废矫 汽俊辑 急琶茄 牧飘费捞 公均牢瘤 炼荤茄促.
function TProxyDesigner.GetFocusedControl(Msg: TMsg): TControl;
var
FocusControl: TControl;
I:Integer;
P:TPoint;
begin
FocusControl:=nil;
if Msg.HWnd=Form.Handle then begin
// 汽 肚绰 WinControl牢 酒囱 促弗 哪欺惩飘甫 急琶茄 版快
FocusControl:=Form.ControlAtPos(Form.ScreenToClient(Msg.Pt),True);
if FocusControl=nil then FocusControl:=Form;
end
else
begin
for I:=0 to Form.ComponentCount-1 do
if (Form.Components[I] is TWinControl) and
(Msg.HWnd=TWinControl(Form.Components[I]).Handle) then
FocusControl:=TControl(Form.Components[I]);
end;
Result:=FocusControl;
end;
// 货肺款 哪欺惩飘甫 Object Inspector狼 哪欺惩飘 格废俊 眠啊茄促.
procedure TProxyDesigner.AddComponentList(Component:TComponent);
begin
ObjectInspector.ComponentList.Items.Add(Component.Name+':'+Component.ClassName);
TProxyForm(Form).ComponentList.Add(Component.Name+':'+Component.ClassName);
end;
// 橇废矫 汽俊辑 惯积窍绰 葛电 皋技瘤甫 贸府茄促.
function TProxyDesigner.IsDesignMsg(Sender: TControl;var Message: TMessage): Boolean;
begin
Result := True;
case Message.Msg of
WM_KEYDOWN: ProcessKeyDown(Message);
WM_KEYUP: ProcessKeyUp(Message);
WM_LBUTTONDOWN: ProcessMouseDown(Sender,Message);
WM_RBUTTONDOWN: ProcessRMouseDown(Sender,Message);
WM_MOUSEMOVE: ProcessMouseMove(Sender,Message);
WM_LBUTTONDBLCLK: ProcessDblClick(Sender,Message);
WM_LBUTTONUP: ProcessMouseUp(Sender,Message);
else Result:= False;
end;
end;
// 橇废矫 汽俊辑 惯积窍绰 MouseDown 皋技瘤甫 贸府茄促.
procedure TProxyDesigner.ProcessRMouseDown(Sender:TControl;Message:TMessage);
var
Menu:TPopupMenu;
Po:TPoint;
// 扑诀 皋春俊 皋春 亲格阑 眠啊茄促.
procedure AddMenuItem(Menu:TPopupMenu;ItemName:string);
var
NewMenuItem:TMenuItem;
begin
NewMenuItem:=TMenuItem.Create(Application);
NewMenuItem.Caption:=ItemName;
NewMenuItem.OnClick:= TProxyForm(Form).OnMenuClick;
Menu.Items.Add(NewMenuItem);
end;
begin
Menu:= TPopupMenu.Create(Form);
AddMenuItem(Menu, 'Bring to Front');
AddMenuItem(Menu, 'Send to Back');
AddMenuItem(Menu, 'Delete');
GetCursorPos(Po);
Menu.Popup(Po.X, Po.Y);
// Form.Dispatch(Message);
end;
// 橇废矫 汽俊辑 惯积窍绰 MouseDown 皋技瘤甫 贸府茄促.
procedure TProxyDesigner.ProcessMouseDown(Sender:TControl;Message:TMessage);
var
Control:TComponent;
begin
// 目辑 困摹俊 乐绰 哪欺惩飘甫 急琶窍绊, 弊 加己阑 Inspector俊 焊咯霖促.
Control:= Sender;
if (Control<>nil) and (TProxyForm(Form).SelectControl <> Sender) then begin
if Control.ClassType=TWrapperControl then
ObjectInspector.DisplayProperty(Control,(Control as TWrapperControl).Component)
else if Control.ClassType<>TGrabHandle then
ObjectInspector.DisplayProperty(nil,Control);
end;
TProxyForm(Form).SelectControl:= Sender;
Form.Dispatch(Message); // 汽俊 皋技瘤甫 傈崔茄促.
end;
// 橇废矫 汽俊辑 惯积窍绰 MouseMove 皋技瘤甫 贸府茄促.
procedure TProxyDesigner.ProcessMouseMove(Sender:TControl;Message:TMessage);
begin
Form.Dispatch(Message);
end;
// 橇废矫 汽俊辑 惯积窍绰 MouseUp 皋技瘤甫 贸府茄促.
procedure TProxyDesigner.ProcessMouseUp(Sender:TControl;Message:TMessage);
begin
Form.Dispatch(Message);
end;
// 橇废矫 汽俊辑 惯积窍绰 DblClick 皋技瘤甫 贸府茄促.
procedure TProxyDesigner.ProcessDblClick(Sender:TControl;Message:TMessage);
begin
with ObjectInspector do begin
SetFocus;
PageControl1.ActivePage:= ObjectInspector.TabEvent;
EventBox.ItemIndex:=0;
EventBoxClick(self);
edEventDblClick(self);
end;
end;
// 橇废矫 汽俊辑 惯积窍绰 KeyDown 皋技瘤甫 贸府茄促.
procedure TProxyDesigner.ProcessKeyDown(Message:TMessage);
begin
case TWMKey(Message).CharCode of
VK_DELETE:
DeleteSelectList;
VK_F11:
ObjectInspector.SetFocus;
VK_F12:
FMainForm.ToggleFormAndUnit;
// VK_SHIFT :
// fMultiSelected:= True
end;
// Form.Dispatch(Message);
end;
// 橇废矫 汽俊辑 惯积窍绰 KeyUp 皋技瘤甫 贸府茄促.
procedure TProxyDesigner.ProcessKeyUp(Message:TMessage);
begin
case TWMKey(Message).CharCode of
VK_SHIFT :
fMultiSelected:= False;
end;
// Form.Dispatch(Message);
end;
procedure TProxyDesigner.UpdateGrabHandle;
begin
fGrabHandles.Update;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -