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

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

← →
Дмитрий К.К. ©   (2003-01-16 09:52) [0]

Здравствуйте, Мастера!
Задача такая: в run-time пройтись по форме (точнее, по компонентам, принадлежащих форме) и если тот или иной компонент имеет определенное свойство, изменить его значение.

Предполагаю, что надо смотреть в сторону ComponentCount, Components, но не могу догадаться, как проверить у компонента НАЛИЧИЕ определенного свойства.


← →
MBo ©   (2003-01-16 09:54) [1]

if GetPropInfo(...)<> nil


← →
stone ©   (2003-01-16 09:55) [2]

GetPropInfo - узнать имеет ли свойство
SetPropValue - изменить его значение


← →
Дмитрий К.К. ©   (2003-01-16 10:31) [3]

Спасибо огромное.


← →
Юрий Зотов ©   (2003-01-16 10:50) [4]

Можно и без проверки - если свойства с указанным именем нет, SetPropValue просто ничего не сделает.


← →
Дмитрий К.К. ©   (2003-01-16 12:02) [5]

Кстати, презабавная вещичка:

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 12:03) [6]

Исправлено только в шестой версии.


← →
Дмитрий К.К. ©   (2003-01-16 15:28) [7]

Мой код не работает :(

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 18:41) [8]

Загляни в исходники.

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-17 07:44) [9]

А как привести типы:

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-17 08:20) [10]

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 08:31) [11]

Чудовищно работоспособный код!


← →
Дмитрий К.К. ©   (2003-01-17 08:32) [12]

Забыл поблагодарить: СПАСИБО!



Страницы: 1 вся ветка

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



Память: 0.47 MB
Время: 0.01 c
14-87141
qwert-AP
2003-01-10 10:41
2003.01.27
Документация по проекту


7-87159
surkis
2002-11-14 13:01
2003.01.27
Права админа для проги


4-87192
Ditron
2002-12-09 18:52
2003.01.27
Доступ к папкам


14-87020
vopros
2003-01-08 09:27
2003.01.27
Павлик вернулся.


3-86619
Nichka
2003-01-05 15:20
2003.01.27
Первая база данных




   Наверх