Форум: "Основная";
Текущий архив: 2002.06.13;
Скачать: [xml.tar.bz2];
ВнизОбъект по имени. Найти похожие ветки
← →
Verq (2002-05-31 23:19) [0]Профи, проучите меня...
Есть строка, как используя её получить доступ к объекту с именем, совпадающим с этой самой строкой?
Например:
string:="qryRashod";
ОбъектПоИмени(string).Dataset......
← →
Новеньки в Делфи (2002-05-31 23:25) [1]FindComponent(string)
в данном случае:
(FindComponent(string)).DataSet...
← →
VID (2002-05-31 23:26) [2]вот те вырезка из help"a
The following example creates 20 edit boxes, using FindComponent with the edit box name to access each newly created edit box.
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
const
NamePrefix = "MyEdit";
begin
for i := 1 to 20 do begin
TEdit.Create(Self).Name := NamePrefix + IntToStr(i);
with TEdit(FindComponent(NamePrefix + IntToStr(i))) do
begin
Left := 10;
Top := i * 20;
Parent := self;
end;
end;
end;
надеюсь поможет. хотя тип объекта всё равно знать надо... без этого в obj pas, насколько мне известно никак. хотя может я и ошибаюсь...
← →
Verq (2002-05-31 23:26) [3]Спасибо.
← →
VID (2002-05-31 23:27) [4]почти одновременно все :)
← →
ION T (2002-06-01 00:24) [5]2VID: RTTI всё стерпит;)
procedure SetIntPropertyIfExists(AComp: TComponent; APropName: string;
AValue: integer);
var PropInfo: PPropInfo;
TK: TTypeKind;
begin
PropInfo := GetPropInfo(AComp.ClassInfo, APropName);
if PropInfo <> nil then
begin
TK := PropInfo^.PropType^.Kind;
if (TK = tkInteger) or (TK = tkInt64) then
SetOrdProp(AComp, PropInfo, AValue);
end;
end;
procedure SetStrPropertyIfExists(AComp: TComponent; APropName: string;
AValue: string);
var PropInfo: PPropInfo;
TK: TTypeKind;
begin
PropInfo := GetPropInfo(AComp.ClassInfo, APropName);
if PropInfo <> nil then
begin
TK := PropInfo^.PropType^.Kind;
if (TK = tkString) or (TK = tkLString) or (TK = tkWString) then
SetStrProp(AComp, PropInfo, AValue);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
NamePrefix = "MyEdit";
var
i: Integer;
Comp: TComponent;
begin
for i := 1 to 20 do begin
TEdit.Create(Self).Name := NamePrefix + IntToStr(i);
Comp:= FindComponent(NamePrefix + IntToStr(i));
SetIntPropertyIfExists(Comp, "left", 10);
SetIntPropertyIfExists(Comp, "top", i* 20);
SetStrPropertyIfExists(Comp, "text", "Edit"+ inttostr(i));
TWinControl(Comp).Parent:= self;
end;
end;
Тока вот с перентом вечная проблема:(( Приходится тайпкаст на винконтрол делать...
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2002.06.13;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.005 c