Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  3 914

•  TDictionary Custom Sort  6 017

•  Fast Watermark Sources  5 805

•  3D Designer  8 617

•  Sik Screen Capture  6 144

•  Patch Maker  6 579

•  Айболит (remote control)  6 567

•  ListBox Drag & Drop  5 428

•  Доска для игры Реверси  95 316

•  Графические эффекты  6 778

•  Рисование по маске  5 943

•  Перетаскивание изображений  4 949

•  Canvas Drawing  5 325

•  Рисование Луны  5 052

•  Поворот изображения  4 594

•  Рисование стержней  3 253

•  Paint on Shape  2 494

•  Генератор кроссвордов  3 378

•  Головоломка Paletto  2 691

•  Теорема Монжа об окружностях  3 465

•  Пазл Numbrix  2 289

•  Заборы и коммивояжеры  2 971

•  Игра HIP  1 938

•  Игра Go (Го)  1 854

•  Симулятор лифта  2 190

•  Программа укладки плитки  1 919

•  Генератор лабиринта  2 362

•  Проверка числового ввода  2 047

•  HEX View  2 366

•  Физический маятник  2 001

 
скрыть

  Форум  

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

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



Delphi Sources

Найти компонент по имени



Оформил: DeeCo

{Instead of writing: / Anstatt so was zu schreiben:}

 Edit1.Text := 'Text 1';
 Edit2.Text := 'Text 2';
 Edit3.Text := 'Text 3';
 Edit4.Text := 'Text 4';
 {...}
 Edit9.Text := 'Text 9';

 {...it's easier to write / ...geht's so einfacher:}

 { 
  Use the forms FindComponent to find a component on the form. 
  TypeCast the Result of FindComponent to the TComponent to be able to use it. 
}


 for i := 1 to 9 do
   TEdit(FindComponent('Edit'+IntToStr(i))).Text := 'Text' + IntToStr(i);

 {or/oder:}

 for i:= 1 to 9 do
   (Findcomponent('Edit'+IntToStr(i)) as TEdit).Text := IntToStr(i);



 { 
  Another example: find a component on any form with 
  a search string like this: 'MyForm10.Edit2' 

  Ein anderes Beispiel: 
  Eine Komponente auf irgendeiner Form finden mittels einer 
  solchen Zeichenfolge: 'MyForm10.Edit2' 
}

 function FindComponentEx(const Name: string): TComponent;
 var
   FormName: string;
   CompName: string;
   P: Integer;
   Found: Boolean;
   Form: TForm;
   I: Integer;
 begin
   // Split up in a valid form and a valid component name 
  P := Pos('.', Name);
   if P = 0 then
   begin
     raise Exception.Create('No valid form name given');
   end;
   FormName := Copy(Name, 1, P - 1);
   CompName := Copy(Name, P + 1, High(Integer));
   Found    := False;
   // find the form 
  for I := 0 to Screen.FormCount - 1 do
   begin
     Form := Screen.Forms[I];
     // case insensitive comparing 
    if AnsiSameText(Form.Name, FormName) then
     begin
       Found := True;
       Break;
     end;
   end;
   if Found then
   begin
     for I := 0 to Form.ComponentCount - 1 do
     begin
       Result := Form.Components[I];
       if AnsiSameText(Result.Name, CompName) then Exit;
     end;
   end;
   Result := nil;
 end;

 procedure TFrom1.Button1Click(Sender: TObject);
 var
   C: TComponent;
 begin
   C := FindComponentEx('MyForm10.Edit2');
   TEdit(C).Caption := 'Hello';
 end;




Похожие по теме исходники

Расширение компонента TEdit

Компонент TDBF

Гадание по имени




Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте