Вниз
Скачать: CL | DM;

Объект по имени.   Найти похожие ветки 

← →
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 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.006 c
3-39960
С.е.р.ж.
2002-05-19 19:12
2002.06.13
Проблемы с выборкой данных из таблиц.


1-40067
I love Warez
2002-05-31 17:05
2002.06.13
Не дадим закрыться консольному окну...


8-40112
DenKop
2002-01-28 22:01
2002.06.13
DirectSound


4-40214
copyr25
2002-04-09 17:07
2002.06.13
Как перехватить нажатие Ctrl+Alt+Del?


14-40171
Olegoz
2002-05-12 01:57
2002.06.13
RAR




   Наверх