unit FindGlob;
interfaceuses
Classes, DsgnIntf, Forms, SysUtils;
function FindGlobalComp (const Name: string;
List: TComponentList): Boolean;
implementationfunction FindGlobalComp (const Name: string;
List: TComponentList): Boolean;
var
I, J, InitCount: Integer;
Form, Comp: TComponent;
begin
InitCount := List.Count;
for I := 0 to Screen.FormCount - 1 dobegin
Form := Screen.Forms[I];
if CompareText(Name, Form.Name) = 0 then
List.Add (Form);
for J := 0 to Form.ComponentCount - 1 dobegin
Comp := Form.Components [J];
if CompareText(Name, Comp.Name) = 0 then
List.Add (Comp);
end;
end;
for I := 0 to Screen.DataModuleCount - 1 dobegin
Form := Screen.DataModules[I];
if CompareText(Name, Form.Name) = 0 then
List.Add (Form);
for J := 0 to Form.ComponentCount - 1 dobegin
Comp := Form.Components [J];
if CompareText(Name, Comp.Name) = 0 then
List.Add (Comp);
end;
end;
// true if found
Result := (List.Count - InitCount) > 0;
end;
end.
unit FindForm;
interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private{ Private declarations }public{ Public declarations }end;
var
Form1: TForm1;
implementation{$R *.DFM}uses
FindGlob, DsgnIntf;
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
Comp: TComponent;
List: TComponentList;
begin
ListBox1.Items.Clear;
List := TComponentList.Create;
tryifnot FindGlobalComp (Edit1.Text, List) then
ListBox1.Items.Add ('No components found')
elsefor I := 0 to List.Count - 1 dobegin
Comp := List.Items[I] as TComponent;
ListBox1.Items.Add (Format (
'%s (%s): %s (%s)',
[Comp.Name, Comp.ClassName,
Comp.Owner.Name, Comp.Owner.ClassName]));
end;
finally
List.Free;
end;
end;
end.
unit SecondF;
interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
private{ Private declarations }public{ Public declarations }end;
var
Form2: TForm2;
implementation{$R *.DFM}end.
Статья Глобальный поиск компонента раздела Компоненты и Классы Компоненты может быть полезна для разработчиков на Delphi и FreePascal.
Комментарии и вопросы
Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.