![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Общее свойство компонентов [D5, Win95/98, WinME, NT4, Win2k, WinXP]
Дмитрий К.К. © (2003-01-16 09:52:00)Здравствуйте, Мастера!
Задача такая: в run-time пройтись по форме (точнее, по компонентам, принадлежащих форме) и если тот или иной компонент имеет определенное свойство, изменить его значение.
Предполагаю, что надо смотреть в сторону ComponentCount, Components, но не могу догадаться, как проверить у компонента НАЛИЧИЕ определенного свойства.
Дмитрий К.К. (2003-01-17 08:32:00) [1]Забыл поблагодарить: СПАСИБО!
Дмитрий К.К. (2003-01-17 08:31:00) [2]Чудовищно работоспособный код!
Юрий Зотов (2003-01-17 08:20:00) [3]procedure TForm1.Button1Click(Sender: TObject);
var
DataSet: TObject;
I: integer;
PropInfo: PPropInfo;
begin
DataSet := GetObjectProp(DataSource1, "DataSet");
for i := 0 to ComponentCount - 1 do
begin
PropInfo := GetPropInfo(Components[i], "DataSet", [tkClass]);
if PropInfo <> nil then
SetObjectProp(Components[i], PropInfo, DataSet)
end
end;
Дмитрий К.К. (2003-01-17 07:44:00) [4]А как привести типы:
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
for I := 0 to ComponentCount - 1 do begin
if GetPropInfo(Components[I], "DataSet") <> nil then
Components[I] ???
end;
end;
Набережных С. (2003-01-16 18:41:00) [5]Загляни в исходники.
procedure SetPropValue(Instance: TObject; const PropName: string;
const Value: Variant);
...
PropInfo := GetPropInfo(Instance, PropName);
if PropInfo = nil then
PropertyNotFound(PropName)// raise exception
else
....
Дмитрий К.К. (2003-01-16 15:28:00) [6]Мой код не работает :(
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
DBSet: Variant;
begin
DBSet := GetPropValue(DataSource1, "DataSet");
for I := 0 to ComponentCount - 1 do begin
// ShowMessage(Components[I].Name);
SetPropValue(Components[I], "DataSet", DBSet);
end;
end;
Подскажите, пожалуйста, почему и как устранить ошибку.
Дмитрий К.К. (2003-01-16 12:03:00) [7]Исправлено только в шестой версии.
Дмитрий К.К. (2003-01-16 12:02:00) [8]Кстати, презабавная вещичка:
Reported by Smola; checked by Jordan Russell
SetPropValue doesn"t work correctly if the property is of Cardinal type. The property will always be assigned 4294967295.
The cause: The function checks if the value is in between the integer range which for the Cardinal type is from 0 to -1 (!) because of casting.
This project reproduces the bug ( http://buglist.jrsoftware.org/generated/files/test0662.zip).
Юрий Зотов (2003-01-16 10:50:00) [9]Можно и без проверки - если свойства с указанным именем нет, SetPropValue просто ничего не сделает.
Дмитрий К.К. (2003-01-16 10:31:00) [10]Спасибо огромное.
stone (2003-01-16 09:55:00) [11]GetPropInfo - узнать имеет ли свойство
SetPropValue - изменить его значение
MBo (2003-01-16 09:54:00) [12]if GetPropInfo(...)<> nil