📄 findcmp.pas
字号:
end;
end;
end;
finally
if (ModuleIntf<>nil) and Forced then
ModuleIntf.CloseModule(True);
ModuleIntf:=nil;
if not Result then
FormIntf :=nil;
CmpIntf :=nil
end;
end;
procedure TFindComponentExpert.DoSearchComponents(InCurrentFormOnly:boolean);//(Sender: TIMenuItemIntf);
var
i,j,c:integer;
strBuf: string;
ModuleIntf: IOTAModule;
FormName:string;
UnitName:string;
ComponentNames:TStrings;
Pr:IOTAProject;
FormIntf:IOTAFormEditor;
MI:IOTAModuleInfo;
begin
strBuf:=CurrentWordInEdit;
if strBuf='' then
Exit;
strBuf:=UpperCase(strBuf);
ComponentNames:=TStringList.Create;
try
UnitName:=GetCurUnitName;
ModuleIntf:=GetIOTAModule(UnitName);
if not InCurrentFormOnly then
begin
{$IFDEF D6+}
c:=Pred(ModuleIntf.OwnerModuleCount);
{$ELSE}
c:=Pred(ModuleIntf.OwnerCount);
{$ENDIF}
for i:=0 to c do
begin
{$IFDEF D6+}
if Supports(ModuleIntf.OwnerModules[i],IOTAProject,Pr) then
{$ELSE}
if Supports(ModuleIntf.Owners[i],IOTAProject,Pr) then
{$ENDIF}
for j:=0 to Pr.GetModuleCount-1 do
begin
MI:=Pr.GetModule(j);
if Assigned(MI) then
FindComponentInForm(MI,UnitName,strBuf,
FormName,ComponentNames,FormIntf
)
end;
end;
end
else
FindComponentInForm(nil,UnitName,strBuf,
FormName,ComponentNames,FormIntf
);
if ComponentNames.Count>0 then
case ComponentNames.Count of
1:
begin
if Assigned(FormIntf) then
begin
strBuf:=CmpNameFromFullPath(ComponentNames[0]);
DoComponentFocus1(FormIntf,strBuf);
end;
end;
else
ShowSearchResult(ComponentNames);
end;
finally
ComponentNames.Free;
FormIntf:=nil
end;
end;
//------------------------------------------------------------------------------
procedure TFindComponentExpert.Execute;// this is MUST to be
begin
end;
function GetIOTAModuleInfo(aProject:IOTAProject;const FileName:string):IOTAModuleInfo;
var
I: Integer;
tmp:IOTAModuleInfo;
begin
Result := nil;
try
for I := 0 to aProject.GetModuleCount - 1 do
begin
tmp:=aProject.GetModule(I);
if tmp.FileName=FileName then
begin
Result:=tmp;
Break;
end;
end;
finally
tmp:=nil
end;
end;
function GetCurrentProjectGroup: IOTAProjectGroup;
var Services: IOTAModuleServices;
Module : IOTAModule;
I: Integer;
begin
Result := nil;
Services := BorlandIDEServices as IOTAModuleServices;
try
for I := 0 to Services.ModuleCount - 1 do
begin
Module := Services.Modules[I];
if Module.QueryInterface(IOTAProjectGroup, Result) = S_OK then
break;
end;
finally
Services :=nil
end;
end;
function GetActiveProject: IOTAProject;
var
pg:IOTAProjectGroup;
begin
pg:=GetCurrentProjectGroup;
try
if Assigned(pg) then
Result:=pg.ActiveProject
else
Result:=nil;
finally
pg:=nil
end;
end;
function GetActiveProjectShortName:string;
var
ap:IOTAProject;
begin
ap:=GetActiveProject;
if Assigned(ap) then
Result:=ExtractFileName(ap.FileName)
else
Result:='Unknown project';
end;
function GetActiveProjectName:string;
var
ap:IOTAProject;
begin
ap:=GetActiveProject;
try
if Assigned(ap) then
Result:=ap.FileName
else
Result:='Unknown project';
finally
ap:=nil
end;
end;
function UnitForFormA(const aFormName:string):string;
var
ap:IOTAProject;
mi:IOTAModuleInfo;
I:Integer;
begin
Result:='';
ap:=GetActiveProject;
try
if Assigned(ap) then
begin
for I := 0 to ap.GetModuleCount - 1 do
begin
mi:=aP.GetModule(I);
if MI.FormName=aFormName then
begin
Result:=MI.FileName;
Exit
end;
end;
end;
finally
ap:=nil
end
end;
function UnitInActiveProject(const UnitName:string):boolean;
var
ap:IOTAProject;
mi:IOTAModuleInfo;
I:Integer;
begin
Result:=False;
ap:=GetActiveProject;
try
if Assigned(ap) then
begin
for I := 0 to ap.GetModuleCount - 1 do
begin
mi:=aP.GetModule(I);
if MI.FileName=UnitName then
begin
Result:=True;
Exit
end;
end;
end;
finally
ap:=nil;
mi:=nil
end;
end;
function GetCurUnitName:string;
var
M:IOTAModule;
begin
Result:='';
M:=(BorlandIDEServices as IOTAModuleServices).CurrentModule;
try
if Assigned(M) then
begin
Result:=M.FileName
end;
finally
M:=nil
end;
end;
function TFindComponentExpert.DoComponentFocus(aProject:IOTAProject;const Path:string):boolean;
var
p,p1:integer;
UnitName:string;
ModuleIntf: IOTAModule;
FormIntf:IOTAFormEditor;
CmpIntf:IOTAComponent;
ComponentName:string;
MInfo:IOTAModuleInfo;
CurProjGroup:IOTAProjectGroup;
begin
Result := False;
if not Assigned(aProject) then
try
CurProjGroup:=GetCurrentProjectGroup;
if Assigned(CurProjGroup) then
begin
for p:=0 to Pred(CurProjGroup.ProjectCount) do
begin
Result:=DoComponentFocus(CurProjGroup.Projects[p],Path);
if Result then
Exit;
end;
end;
finally
CurProjGroup:=nil;
end;
if not Assigned(aProject) then
Exit;
p:=Pos('#UNIT#', Path);
UnitName :=Copy(Path,p+6,MaxInt);
p:=Pos(':',Path);
p1:=Pos('.',Path);
ComponentName:=Copy(Path,p1+1,p-p1-1);
ModuleIntf:=GetIOTAModule(UnitName);
if not Assigned(ModuleIntf) then
begin
MInfo:=GetIOTAModuleInfo(aProject,UnitName);
if assigned(MInfo) then
ModuleIntf:=MInfo.OpenModule
end;
if Assigned(ModuleIntf) then
try
FormIntf :=GetFormEditor(ModuleIntf);
CmpIntf:=FormIntf.FindComponent(ComponentName);
if Assigned(CmpIntf) then
begin
CmpIntf.Select(False);
ShowOI;
FormIntf.Show;
Result := True;
end;
finally
MInfo :=nil;
ModuleIntf:=nil;
FormIntf :=nil;
CmpIntf :=nil;
end;
end;
procedure TFindComponentExpert.ShowOI;
begin
if OI <>nil then
begin
OI.Enabled:=True;
if OI.Enabled then
begin
OI.Show;
end;
end;
end;
function TFindComponentExpert.GetOI: TForm;
var
j : integer;
begin
Result := nil;
with Screen do
for J := 0 to Pred(FormCount) do
if Forms[j].ClassName = 'TPropertyInspector' then
begin
Result := Forms[j];
Break
end;
end;
function TFindComponentExpert.CmpNameFromFullPath(const Path:string):string;
var
p,p1:Integer;
begin
p:=Pos(':',Path);
p1:=Pos('.',Path);
Result:=Copy(Path,p1+1,p-p1-1);
end;
function TFindComponentExpert.DoComponentFocus1(FormIntf: IOTAFormEditor;
const ComponentName: string): boolean;
var
CmpIntf:IOTAComponent;
begin
CmpIntf:=FormIntf.FindComponent(ComponentName);
if Assigned(CmpIntf) then
try
CmpIntf.Select(False);
ShowOI;
FormIntf.Show;
Result := True;
finally
CmpIntf:=nil
end
else
Result := False;
end;
initialization
finalization
FindComponentExpert:=nil
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -