Ver Mensaje Individual
  #1  
Antiguo 30-05-2007
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - Espańa
Posts: 18.275
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
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
    ...
Responder Con Cita