скрыть

скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Google  
 

Глобальный поиск компонента





unit FindGlob;

interface

uses
  Classes, DsgnIntf, Forms, SysUtils;

function FindGlobalComp (const Name: string;
  List: TComponentList): Boolean;

implementation

function 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 do
  begin
    Form := Screen.Forms[I];
    if CompareText(Name, Form.Name) = 0 then
      List.Add (Form);
    for J := 0 to Form.ComponentCount - 1 do
    begin
      Comp := Form.Components [J];
      if CompareText(Name, Comp.Name) = 0 then
        List.Add (Comp);
    end;
  end;
  for I := 0 to Screen.DataModuleCount - 1 do
  begin
    Form := Screen.DataModules[I];
    if CompareText(Name, Form.Name) = 0 then
      List.Add (Form);
    for J := 0 to Form.ComponentCount - 1 do
    begin
      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;

interface

uses
  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;
  try
    if not FindGlobalComp (Edit1.Text, List) then
      ListBox1.Items.Add ('No components found')
    else
      for I := 0 to List.Count - 1 do
      begin
        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;

interface

uses
  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.

Загрузить весь проект






Copyright © 2004-2016 "Delphi Sources". Delphi World FAQ




Группа ВКонтакте   Ссылка на Twitter   Группа на Facebook