Как выяснить имеет ли объект определённое свойство
Автор: http://www.lmc-mediaagentur.de
function hasprop(comp: TComponent; const prop: string): Boolean;
var
proplist: PPropList;
numprops, i: Integer;
begin
result := false;
getmem(proplist, getTypeData(comp.classinfo)^.propcount * Sizeof(Pointer));
try
NumProps := getproplist(comp.classInfo, tkProperties, proplist);
for i := 0 to pred(NumProps) do
begin
if comparetext(proplist[i]^.Name, prop) = 0 then
begin
result := true;
break;
end;
end;
finally
freemem(proplist, getTypeData(comp.classinfo)^.propcount * Sizeof(Pointer));
end;
end;
procedure setcomppropstring(comp: TComponent; const prop, s: string);
var
proplist: PPropList;
numprops, i: Integer;
begin
getmem(proplist, getTypeData(comp.classinfo)^.propcount * Sizeof(Pointer));
try
NumProps := getproplist(comp.classInfo, tkProperties, proplist);
for i := 0 to pred(NumProps) do
begin
if (comparetext(proplist[i]^.Name, prop) = 0) and
(comparetext(proplist[i]^.proptype^.name, 'string') = 0 then
begin
setStrProp(comp, proplist[i], s);
break;
end;
end;
finally
freemem(proplist, getTypeData(comp.classinfo)^.propcount * Sizeof(Pointer));
end;
end;
|