DELPHI FAQ: Как выяснить имеет ли объект определённое свойство?


Как выяснить имеет ли объект определённое свойство?
Previous  Home  Next




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) = 0and
         (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
;


Взято из http://www.lmc-mediaagentur.de/dpool






DELPHI FAQ




EOMY TOP 100      Рейтинг@Mail.ru      Rambler's Top100