FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
|||
|
|||
Saber si existen propiedades
Existe alguna funcion para saber si existen propiedades en los componentes. Pj. Saber si existe la propiedad visible en un componente
|
#2
|
|||
|
|||
Para eso necesitas un poquito de RTTI
Código:
var PropInfo : PPropInfo; Component : TComponent; begin for i := 0 to Form.ComponentCount - 1 do begin Component := Form.Components[i]; // Miramos si tiene la propiedad CAPTION PropInfo := GetPropInfo( Component.ClassInfo, 'Caption' ); if Assigned(PropInfo) then SetStrProp(Component, 'Caption', GetIdioma(GetStrProp(Component, 'Hola'))); end; MODIF.: se me habia olvidado comentar que has de añadir en el uses la unit TypInfo en que le encontrarás otras funciones SetXXXX y GetXXXX según la necesidad del tipo de variable Última edición por __cadetill fecha: 31-03-2004 a las 11:59:12. Razón: Olvido |
#3
|
|||
|
|||
Muchas gracias
|
#4
|
||||
|
||||
Propiedades publicadas
¡Buen día a todos!
Cabe destacar que la información de tiempo de ejecución que arrojan las funciones de la unidad TypInfo, se aplica básicamente a los elementos publicados de las clases (sección Published), es decir a las propiedades y eventos que normalmente son visibles en el inspector de objetos. Por lo cual, si una clase de objeto cuenta con una propiedad pública (Public no Published) llamada "Visible", el compilador no generará para ella información de tiempo de ejecución que pueda ser obtenida con las funciones de la unidad TypInfo. En general, me parecen muy útiles las funciones de la unidad TypInfo. Gracias a ellas, he podido crear algunas funciones que facilitan ciertas operaciones en lote sobre un grupo de componentes. ¡Saludos! Al González . |
#5
|
||||
|
||||
Duda...
Hola Al!
A ver si me ha quedado claro, 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? Un saludillo! |
#6
|
||||
|
||||
¡Buen día a todos! Hola Nuria.
Cita:
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; Al González . |
#7
|
||||
|
||||
Hola Al!
Gracias por la aclaración me ha servido mucho. Un saludito...Nos leemos... |
|
|
|