![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Не могу FindComponent динамически созданый компонент.
NeyroSpace © (2002-09-16 15:25:00)Создаю динамически компонент на TabSheet1, но FindComponent его потом не находит. Хелп!
lenin (2002-09-16 15:58:00) [1]Наверно мона так:
procedure TForm1.FormCreate(Sender: TObject);
var n:integer;
comp:TComponent;
begin
with TEdit.Create(TabSheet1) do//self
Name:="Edit";
Parent:=TabSheet1;
Text := String(Edit.Name);
end;
Form1.caption:= (TabSheet1.FindComponent("Edit") as TEdit).Text;
end;
У меня работает.
NeyroSpace (2002-09-16 15:49:00) [2]А если я создаю так:
procedure TForm1.FormCreate(Sender: TObject);
var n:integer;
comp:TComponent;
begin
Edit := TEdit.Createparented(TabSheet1.Handle);//self
Edit.Name:="Edit";
Edit.Parent:=TabSheet1;
Edit.Text := "";
Edit.Text := String(Edit.Name);
ParentComp := nil;
ParentComp := TWinControl(TabSheet1.FindComponent("Edit"));
Form1.caption:= TEdit(ParentComp).Text;
end;
Anatoly Podgoretsky (2002-09-16 15:46:00) [3]FindComponent не применим в твоем случае, у него нет сообственика
McSimm (2002-09-16 15:42:00) [4]>Edit := TEdit.Create(nil);
И не должен находить.
Indicates whether a given component is owned by the component.
Или пиши
Edit := TEdit.Create(TabSheet1);
Или ищи в списке Controls
Song (2002-09-16 15:42:00) [5]Интересно... Parent устанавливаете в TTabSheet, а ищите на TForm :)
NeyroSpace (2002-09-16 15:40:00) [6]unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Edit:TEdit;
ParentComp:TWinControl;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var n:integer;
comp:TComponent;
begin
Edit := TEdit.Create(nil);
Edit.Name:="Edit";
Edit.Parent:=TabSheet1;
Edit.Text := "";
Edit.Text := String(Edit.Name);
ParentComp := nil;
//ParentComp := TWinControl(Form1.FindComponent("Edit1"));
//ParentComp := TWinControl(TabSheet1.FindComponent("Edit1"));
ParentComp := TWinControl(Form1.FindComponent("Edit"));
//if ParentComp<>nil then Form1.caption:= TEdit(ParentComp).Text;
//Form1.caption:= TEdit(ParentComp).Text;
Form1.caption:= TEdit(Form1.FindComponent("Edit")).text;
for n := 0 to Form1.ComponentCount-1 do
begin
// Comp := Form1.Components[n];
Comp := TabSheet1.Components[n];
MessageBox(0,Pchar((Comp).Name),"",mb_ok);
end;
end;
end.
Это код безуспешных попыток...
lenin (2002-09-16 15:38:00) [7]TabSheet1.FindComponent(), или у тебя не указано имя.
Anatoly Podgoretsky (2002-09-16 15:29:00) [8]Приведи код