FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
|||
|
|||
Tipo de Propiedades y valor de una clase u objeto TypInfo
En realidad no se si estoy haciendo correctamente la pregunta
Aqui mi unidad, solo un formulario (Form1) y un boton (btnPrueba)
Apartir de la clase Producto = Class(TPersistent) Donde estan definidos sus tipos, quiero por medio de TypInfo o RTTI Obtener las propiedades y sus respectivos valores. Vale aclarar que la clase Producto es mucho mas extensa y esta definida en otra unidad, aqui esta resumida para el caso practico. Con el procedimiento GetPropertyList(Producto, Lista, tkProperties); Obtengo la lista de propiedades de Producto y se carga en Lista: TStringList Luego recorriendo ese TStringList obtengo cada uno de los valores y su tipo Value := GetPropValue(Producto, Lista[i]); PInfo := GetPropInfo(Producto, Lista[i]); Mi problema es que al ver los valores siguientes FCreado:TDateTime; FClaves:TStringList; Estos me devuelven numeros de tipo float Supongamos que en el caso del TDateTime esto sea correcto porque se maneja asi... Como hago para que eso que me devuelve lo pase a fecha (dd/mm/yyyy) que el usuario ve, siendo que el tipo devuelto es un tkfloat, el usuario no entiende ese numero float, yo tengo que mostrarle la fecha. En el caso de claves es mas complicado porque lo que me devuelve tambien es un numero float, pero el tipo es un tkClass, como hago para sacar los valores que tiene ese stringlist Lo que pensaba era, volver a la funcion, donde le paso la clase producto apuntando a claves que es lo que quiero que me devuelva ahora... pero la lista la deja vacia, como que no encuentra ese elemento GetPropertyList(Producto.Claves, Lista2, tkProperties); Tambien probe con este procedimiento, tambien me devuelve la lista vacia GetPropertyNames(Producto.Claves, Lista);
|
#2
|
|||
|
|||
Hola,
Para el caso de la propiedad TDateTime basta con usar formatdatetime, para la propiedad TStringList, el valor que te da es un puntero a memoria y puedes hacer un cast, puedes usar la propiedad classname para asegurarte, si haces el cast con una clase distinta, es fácil que obtengas mensajes de Access violation. Saludos. |
#3
|
||||
|
||||
Yo revisaría los procedimientos y funciones de la unit TypInfo especiales para Clases.
Por ejemplo, puedes hacer algo como esto, sabiendo que la propiedad claves es de tipo "Class":
Con eso obtendrás un puntero al objeto el objeto Claves y si preguntan por su ClassName, verás que te devuelve "TStringList". También hay otra llamada, GetObjectPropClass que te puede ser útil.
__________________
Germán Estévez => Web/Blog Guía de estilo, Guía alternativa Utiliza TAG's en tus mensajes. Contactar con el Clubdelphi P.D: Más tiempo dedicado a la pregunta=Mejores respuestas. |
#4
|
|||
|
|||
Gracias Neftali, justamente estaba viendo las funciones que propones, les dejo un pequeño resumen de como lo estoy resolviendo, por si a alguno le interesa. Por ahora para ir tomando la idea estoy guardando los datos obtenidos en un array dinamico. Y con el procedimiento recursivo.
Última edición por elarys fecha: 30-07-2012 a las 21:08:12. |
#5
|
|||
|
|||
|
#6
|
||||
|
||||
5 lineas, son 5 líneas...
__________________
Germán Estévez => Web/Blog Guía de estilo, Guía alternativa Utiliza TAG's en tus mensajes. Contactar con el Clubdelphi P.D: Más tiempo dedicado a la pregunta=Mejores respuestas. |
|
|
Temas Similares | ||||
Tema | Autor | Foro | Respuestas | Último mensaje |
Publicar parte de un objeto de clase | jlrbotella | OOP | 7 | 19-07-2017 09:18:54 |
Crear Objeto por su nombre de clase | jlrbotella | OOP | 2 | 08-01-2008 23:44:37 |
Acceso a las propiedades de un objeto desde el editor de propiedades | Hugo | OOP | 0 | 24-11-2006 12:58:22 |
Clase, objeto, tipo? | [Gunman] | OOP | 3 | 04-01-2006 16:11:32 |
Metodo que devuelva la lista de propiedades de la clase. | nemo | OOP | 1 | 16-07-2003 16:10:02 |
|