Ver Mensaje Individual
  #6  
Antiguo 02-04-2004
Avatar de Al González
[Al González] Al González is offline
In .pas since 1991
 
Registrado: may 2003
Posts: 5.604
Reputación: 29
Al González Es un diamante en brutoAl González Es un diamante en brutoAl González Es un diamante en brutoAl González Es un diamante en bruto
Smile

¡Buen día a todos! Hola Nuria.


Cita:
Empezado por Nuria
...un objecto tiene una propiedad public. Cuando estoy en tiempo de ejecución no puedo saber si ese objeto tiene dicha propiedad... , no hay manera de saberlo?...
Efectivamente, en tiempo de ejecución no hay forma de saber si un objeto tiene una propiedad pública que lleve cierto nombre. La información RTTI de nombres y tipos de propiedades, se genera sólo para las propiedades publicadas de los objetos.


Esto tiene que ver con la directiva de compilación $TYPEINFO/$M:

The $M switch directive controls generation of runtime type information (RTTI). When a class is declared in the {$M+} state, or is derived from a class that was declared in the {$M+} state, the compiler generates runtime type information for fields, methods, and properties that are declared in a published section. If a class is declared in the {$M-} state, and is not derived from a class that was declared in the {$M+} state, published sections are not allowed in the class. Note that if a class is forward declared, the first declaration of the class must be declared with the $M switch.

When the $M switch is used to declare an interface, the compiler generates runtime type information for all properties and methods. That is, for interfaces, all members are treated as if they were published.

Note: The TPersistent class defined in the Classes unit of the component library is declared in the {$M+} state, so any class derived from TPersistent will have RTTI generated for its published sections. The component library uses the runtime type information generated for published sections to access the values of a component's properties when saving or loading form files. Furthermore, the IDE uses a component's runtime type information to determine the list of properties to show in the Object Inspector.



Código de la función IsPublishedProp (¿Es Propiedad Publicada?), de la unidad TypInfo (Delphi 7):
Código:
function IsPublishedProp(Instance: TObject; const PropName: string): Boolean;
begin
  Result := GetPropInfo(Instance, PropName) <> nil;
end;
Espero esto sea de utilidad. Seguimos en contacto.

Al González .
Responder Con Cita