Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Saber si un comp. tiene una propiedad (RTTI) (https://www.clubdelphi.com/foros/showthread.php?t=80802)

Neftali [Germán.Estévez] 30-05-2007 13:32:45

Saber si un comp. tiene una propiedad (RTTI)
 
Es una sencilla función que devuelve True o False segun si un componente (TObject) tiene una propiedad published o no.
Utiliza RTTI así que hay que hay que añadir al USES la unit TypInfo.

Código Delphi [-]
// Devuelve si existe o no una propiedad en un Objeto (RTTI).
function ExistProp(Instance: TObject; const PropName: string):Boolean;
var
  PropInfo: PPropInfo;
begin
  // Busca la propiedad y devuelve segun si la estructura = nil
  PropInfo := GetPropInfo(Instance, PropName);
  Result := not (PropInfo = nil);
end;

Para probarla podéis añadir un código similar a este:

Código Delphi [-]
  // Tiene la propiedad Lines?
  if ExistProp(Memo1, 'Lines') then begin
    ...


La franja horaria es GMT +2. Ahora son las 21:48:17.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi