![]() |
![]() ![]() ![]() ![]() |
|
Как установить значение строкового или целого поля если оно присутствуетDelphi , Компоненты и Классы , RTTIАвтор: Xavier Pacheco I am building a routine that checks our forms for validity before deploying them. I would like to use some kind of structure that tests if a component type has access to a certain property, something like: " if (self.Controls[b] has Tag) then ...". Can anyone offer suggestions? Here's an example of setting a string property for a component if it exists and another for an integer property:
procedure SetStringPropertyIfExists(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 SetIntegerPropertyIfExists(AComp: TComponent; APropName: string;
AValue: Integer);
var
PropInfo: PPropInfo;
begin
PropInfo := GetPropInfo(AComp.ClassInfo, APropName);
if PropInfo <> nil then
begin
if PropInfo^.PropType^.Kind = tkInteger then
SetOrdProp(AComp, PropInfo, AValue);
end;
end;
Установка значения строкового или целого поля в компоненте при его наличии может быть выполнена с помощью процедур SetStringPropertyIfExists и SetIntegerPropertyIfExists, которые проверяют тип свойства переданным значением и выполняют соответствующие опер Комментарии и вопросыПолучайте свежие новости и обновления по Object Pascal, Delphi и Lazarus прямо в свой смартфон. Подпишитесь на наш
|
||||
©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007 | ||||