⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findcmp.pas

📁 FIBPlus is a component suite intended for work with InterBase. It is direct, fast and flexible Inter
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit FindCmp;

interface
{$I FIBPlus.inc}
{$IFDEF D6+}
 {$WARN UNIT_DEPRECATED OFF}
{$ENDIF}
uses
  SysUtils, Windows, Controls, EditIntf, ExptIntf, Menus,
  ToolsAPI,  Classes, Forms, StdCtrls, ExtCtrls,TypInfo,StFilSys;

type

TFindComponentExpert=class(TIExpert)
private
  OI:TForm;
  FCurrentUnit:string;

  function  GetOI:TForm;
  function  CmpNameFromFullPath(const Path:string):string;

public
  constructor Create; virtual;
  destructor  Destroy; override;

  function  GetIDString: string; override;
  function  GetName: string; override;
  function  GetState: TExpertState; override;
  function  GetAuthor: string; override;
  function  GetComment: string; override;
  function  GetPage: string; override;
  function  GetStyle: TExpertStyle; override;
  function  GetMenuText: string; override;
  function  GetGlyph: HICON; override;

  procedure Execute; override;
  procedure DoSearchComponents(InCurrentFormOnly:boolean);

  function  CurrentWordInEdit: string;
  function  FindComponentInForm(MI:IOTAModuleInfo;var UnitName, ComponentName:string;
   var aFormName:string; ComponentNames:TStrings; var FormIntf:IOTAFormEditor
  ):boolean;

  function  DoComponentFocus(aProject:IOTAProject;const Path:string):boolean; 
  function  DoComponentFocus1(FormIntf:IOTAFormEditor;const ComponentName:string):boolean;

  procedure ShowOI;
end;

function GetCurrentProjectGroup: IOTAProjectGroup;
function GetActiveProject: IOTAProject;
function GetActiveProjectShortName:string;
function GetActiveProjectName:string;
function UnitForFormA(const aFormName:string):string;
function UnitInActiveProject(const UnitName:string):boolean;
function GetCurUnitName:string;

function GetIOTAModule(const FileName:string):IOTAModule;


procedure Register;

var
  FindComponentExpert:TFindComponentExpert;

implementation

uses
  uFrmSearchResult ;

//------------------------------------------------------------------------------
procedure Register;
begin
  RegisterLibraryExpert(TFindComponentExpert.Create);
end;
//------------------------------------------------------------------------------
constructor TFindComponentExpert.Create;
begin
  inherited Create;
  FindComponentExpert:=Self;
  OI:=GetOI;
end;
//------------------------------------------------------------------------------
destructor TFindComponentExpert.Destroy;
begin
  inherited Destroy;
end;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function TFindComponentExpert.GetPage: string;
begin
  Result:=''; // Only for experts by type Form & Project
end;
//------------------------------------------------------------------------------
function TFindComponentExpert.GetMenuText: string;
begin
   // Only for experts by type Form Standart
end;
//------------------------------------------------------------------------------
function TFindComponentExpert.GetComment: string;
begin
  // Only for experts by type Form & Project
end;
//------------------------------------------------------------------------------
function TFindComponentExpert.GetStyle: TExpertStyle;
begin
  Result:=esAddIn;
end;
//------------------------------------------------------------------------------
function TFindComponentExpert.GetAuthor: string;
begin
  Result:='Plotnikov Yuri & Serge Buzadzhy';// Only for experts by type Form & Project
end;
//------------------------------------------------------------------------------
function TFindComponentExpert.GetGlyph: HICON;
begin
  Result:=0; // Only for experts by type Form & Project
end;
//------------------------------------------------------------------------------
function TFindComponentExpert.GetName: string;
begin
  Result:='Find Component(s)';
end;
//------------------------------------------------------------------------------
function TFindComponentExpert.GetState: TExpertState;
begin
  Result:=[esEnabled];
end;
//------------------------------------------------------------------------------
function TFindComponentExpert.GetIDString: string;
begin
  Result:='{B1A9B8BF-38F6-42DD-8849-04BBC794D7BF}'
end;

function    TFindComponentExpert.CurrentWordInEdit: string;
const
  LexemSymbols=['A'..'Z','a'..'z', '_', '0'..'9'];
var
   iWSep1, iWSep2:      Integer;

  CurPos :     TOTACharPos;
  CursorPos :TOTAEditPos;

  pstrBuf: PAnsiChar;
  isStringsPropFile:boolean;
  FSystem:string;
  curModule:IOTAModule;
  curEditor:IOTAEditor;
  EditView:IOTAEditView;
  EditReader:IOTAEditReader;
  II:IUnknown;
begin
  Result := '';
  FCurrentUnit:=GetCurUnitName;

  If FCurrentUnit='' then
   Exit; // No module

  if Copy(UpperCase(FCurrentUnit),Length(FCurrentUnit)-3,MaxInt)='DFM' then
  begin // this is a form
    Exit;
  end;


  curModule:=(BorlandIDEServices as IOTAModuleServices).CurrentModule;

  if not Assigned(curModule) then
   Exit;

  FSystem:=curModule.FileSystem;
  isStringsPropFile:=FSystem=sTStringsFileSystem;
  if isStringsPropFile then
  begin
    FCurrentUnit:=UpperCase(FCurrentUnit);
    {$IFDEF D9+}
       FCurrentUnit:=Copy(FCurrentUnit,5,MaxInt);
    {$ENDIF}
    iWSep2:=1;
    for iWSep1:=Length(FCurrentUnit)-3 downto 1 do
    begin
      if FCurrentUnit[iWSep1]=DotSep then
      begin
        iWSep2:=iWSep1;
        Break
      end;
    end;
    SetLength(FCurrentUnit,iWSep2-1);

    iWSep2:=0;
    for iWSep1:=Length(FCurrentUnit) downto 1 do
    begin
      if FCurrentUnit[iWSep1]=DotSep then
      begin
        iWSep2:=iWSep1;
        Break
      end;
    end;
    FCurrentUnit:=Copy(FCurrentUnit,iWSep2+1,MaxInt);
    Result:=FCurrentUnit;
    Exit;
  end;

  {$IFDEF D6+}
   curEditor:=curModule.CurrentEditor;
  {$ELSE}
   for iWSep1:=curModule.GetModuleFileCount-1 downto 0 do
   begin
    curEditor:=curModule.GetModuleFileEditor(iWSep1);
    if Supports(curEditor,IOTASourceEditor,II) then
     Break;
   end;
  {$ENDIF}
  if not Supports(curEditor,IOTASourceEditor,II) then
   Exit;
  if (curEditor as IOTASourceEditor).GetEditViewCount=0 then
    Exit;
  EditView:=(curEditor as IOTASourceEditor).GetEditView(0);

  EditReader:=(curEditor as IOTASourceEditor).CreateReader;
  GetMem(pstrBuf,2000);
  try
   CursorPos:=EditView.CursorPos;
   EditView.ConvertPos(True,CursorPos,CurPos);
   CursorPos.Col:=CurPos.CharIndex;
   CurPos.CharIndex:=0;
   EditReader.GetText(EditView.CharPosToPos(CurPos),pstrBuf,2000);
   iWSep1:=CursorPos.Col;
   if not(pstrBuf[iWSep1] in LexemSymbols) then
    if (iWSep1>0) and (pstrBuf[iWSep1-1] in LexemSymbols) then
     Dec(iWSep1)
    else
     if (pstrBuf[iWSep1+1] in LexemSymbols) then
      Inc(iWSep1)
     else
       Exit;
   iWSep2:=iWSep1;

   while (iWSep1>0) and (pstrBuf[iWSep1-1] in LexemSymbols) do
     Dec(iWSep1);

   while (iWSep2<2000) and (pstrBuf[iWSep2+1] in LexemSymbols) do
    Inc(iWSep2);

   SetLength(Result,iWSep2-iWSep1+1);
   if iWSep2>=iWSep1 then
     Move(pstrBuf[iWSep1],Result[1],iWSep2-iWSep1+1);

  finally
    FreeMem(pstrBuf,2000);
  end;
end;

function GetIOTAModule(const FileName:string):IOTAModule;
var
  Services: IOTAModuleServices;
  I: Integer;
begin
  Result := nil;
  Services := BorlandIDEServices as IOTAModuleServices;
  for I := 0 to Services.ModuleCount - 1 do
  begin
    if Services.Modules[I].FileName=FileName then
    begin
        Result:=Services.Modules[I];
        Break;
    end;
  end;
end;



function GetFormEditor(Module: IOTAModule): IOTAFormEditor;
var
 i,j:integer;
 s:string;
 FormModule:IOTAModule;
begin
  Result := nil;
  if not Assigned(Module) then
   Exit;
  for i := 0 to Module.GetModuleFileCount - 1 do
  begin
   if Supports(Module.GetModuleFileEditor(i), IOTAFormEditor, Result) then
    Exit;
  end;
  s:=Module.GetFileSystem;
  if s='' then
  else
  begin
    s:=Module.FileName;
    {$IFDEF D9+}
     s:=Copy(s,5,MaxInt);
    {$ENDIF}
    j:=Length(s);
    for i := 1 to Length(s)  do
    begin
      if s[i]=DotSep then
      begin
        j:=i-1;
        Break
      end;
    end;
    SetLength(s,j);
    FormModule:=(BorlandIDEServices as IOTAModuleServices).FindFormModule(s);
    if Assigned(FormModule) then
    begin
      for i := 0 to FormModule.GetModuleFileCount - 1 do
      begin
       if Supports(FormModule.GetModuleFileEditor(i), IOTAFormEditor, Result) then
        Exit;
      end;
      FormModule:=nil
    end;
  end;

end;
//------------------------------------------------------------------------------

function  TFindComponentExpert.FindComponentInForm(MI:IOTAModuleInfo;var UnitName, ComponentName:string;
   var aFormName:string; ComponentNames:TStrings;var FormIntf:IOTAFormEditor
):boolean;
var
  ModuleIntf: IOTAModule;
  Forced:boolean;
  RootComponent:IOTAComponent;
  CmpIntf:IOTAComponent;
  i:integer;
  CurName:string;
begin
  Result:= False;
  Forced:=False;
  FormIntf:=nil;
  if MI=nil then
   ModuleIntf:=GetIOTAModule(UnitName)
  else
  begin
   UnitName:=MI.FormName;
   if  Length(UnitName)=0 then
    Exit;
   UnitName:=MI.FileName;
   ModuleIntf:=GetIOTAModule(UnitName);
   if (ModuleIntf=nil) and (UnitName<>'') then
   begin
     ModuleIntf:=MI.OpenModule;
     Forced:=True;
   end;
  end;
  FormIntf  :=GetFormEditor(ModuleIntf);
  try
   if Assigned(FormIntf) then
   begin
     RootComponent  :=FormIntf.GetRootComponent;
     RootComponent.GetPropValueByName('Name',aFormName);
     for i:=0 to Pred(RootComponent.GetComponentCount) do
     begin
       RootComponent.GetComponent(i).GetPropValueByName('Name',CurName);
//       if Pos(ComponentName,UpperCase(CurName))=1 then
       if ComponentName=UpperCase(CurName) then
       begin
        ComponentNames.Add(aFormName+'.'+CurName+
         ':'+RootComponent.GetComponent(i).GetComponentType+'#UNIT#'+UnitName);
        Result := True;
        Exit;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -