FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
|||
|
|||
¿Cómo 'casteo' un TCollection?
Tengo mi Objeto es algo asi simplificado
Y en donde TATS_List es una coleccion de objetos Ahora con el siguiente procedimiento leo las propiedades de dicho objeto Nambre y valores Pero cuando llega al TATS_List que es de tipo TCollection, no lee y pasa al siguiente elemento Puedo castear, sabiendo que TATS_List es de tipo TCollection y obtener los valores de esa forma???
Por el momento esto me devuelve un stringlist y los datos de mi objeto simplificado para no hacerlo largo y que se entienda Noten que Tipo que seria mi TCollection RTTI o TypInfo no lee los datos, siendo que mi objeto si tiene datos <Codes> <Code>1</Code> <Name>A</Name> <Tipo></Tipo> <Code>2</Code> <Name>B</Name> <Tipo></Tipo> <Code>3</Code> <Name>C</Name> <Tipo></Tipo> </Codes> Mi idea es castear el TCollection para ver si de ahi puedo leer los datos, pero si hay alguna otra manera bienvenida sea La clase TATS_List funciona correctamente, y me carga los datos a mi objeto... Luego le paso al procedure mi objeto en tiempo de ejecucion y que haga el trabajo, pero nada Edito porque hice nuevas pruebas NOTA: probe pasando todo mi codigo TCollection con un TStringList, con un TList, TStrings, etc, etc, debe ser porque ninguno de estos tienen propiedad published, se les ocurre algun otro contenedor de objetos, o similares como stringlist Parece que RTTI no lee propiedades publicas. Acabo de hacer otra prueba, agregando un nuevo valor simulando que es mi collection pero ahora de un solo campo de tipo Array of String Al ser public Items mi procedimiento no lo puede leer Probe pasarlo a published, pero delphi me da error Items no puede ser published por ser un array Estoy trabajando con delphi 2007 y por ahora no podemos mudarnos si tienen soluciones con delphi mas nuevos
Última edición por elarys fecha: 13-09-2012 a las 21:17:26. |
#2
|
||||
|
||||
Hola elarys
Lo que puedo entender es que quieres generar un XML a partir de una clase que haz creado. De casualidad ahorita estoy trabajando en un proyecto donde debo llevar a XML valores de un componente que contiene una o varias TCollection y en algunos casos TCollection dentro de TCollection. Probé tu solución y si sucede que al llegar a la TCollection no encuentra ninguna información. Leí un poco antes de contestarte y al parecer delphi no sabe exactamente como leer tu TElarysCollection (Me imagino que habrás creado un calse heredada de TCollection) y por eso la salta sin ofrecer ningun resultado. (Si entendí mal agradecería que alguien pueda aclararnos porque no lee el cntenido de la TCollection) Esto es lo que obtuve al ejecutar tu funcion Código:
<KplGenPlan> <CanEjecuciones>0</CanEjecuciones> <CodDefi>KNMPLDMO</CodDefi> <CodPlan>KNMPLDMO_PL001</CodPlan> <CodProg>KNmPldmo</CodProg> <KplDbConnection> <KplDbBdeParams> <Database> <AliasName>Kactus7</AliasName> <Connected>True</Connected> <DatabaseName>DBKactus</DatabaseName> <DriverName></DriverName> <Exclusive>False</Exclusive> <HandleShared>False</HandleShared> <KeepConnection>True</KeepConnection> <LoginPrompt>True</LoginPrompt> <Name>DtbKactus</Name> <StringList> </StringList> <ReadOnly>False</ReadOnly> <SessionName>Default</SessionName> <Tag>0</Tag> <TransIsolation>tiReadCommitted</TransIsolation> </Database> <DatabaseName>DBKactus</DatabaseName> <Driver>KDBDrvOracle</Driver> <Password>digital</Password> <ShowLoginForm>True</ShowLoginForm> <Username>Kactus</Username> </KplDbBdeParams> <Connected>True</Connected> <Name>KplDbConn</Name> <Tag>0</Tag> <TipoConnecion>KDtcBDE</TipoConnecion> </KplDbConnection> <Estado>kplPlanEstInac</Estado> <FinalizacionValor>kplFinProgNoValid</FinalizacionValor> <FormString>FrmNmPldmo</FormString> <Name>KplGenPlan</Name> <NombrePlan></NombrePlan> <KplNotificacion> <Activo>True</Activo> <Email>sdasd</Email> <StringList> </StringList> <Titulo>sadasdasd</Titulo> </KplNotificacion> <Observacion></Observacion> <KplProgramacion> <FechaEjecucion>41182,8333333333</FechaEjecucion> <FechaFinal>41143,6895889468</FechaFinal> <FechaInicio>41144</FechaInicio> <FrecuenciaDiaNum>0</FrecuenciaDiaNum> <FrecuenciaDiaVar>kplDiaVarUltDiaMes</FrecuenciaDiaVar> <FrecuenciaTipo>kplFrecTipMensu</FrecuenciaTipo> <Hora>0,833333333333333</Hora> <TieneVencimiento>False</TieneVencimiento> </KplProgramacion> <Tag>0</Tag> <VersionProg>12.6.0.5</VersionProg> <StringList> </StringList> </KplGenPlan> Código:
<?xml version="1.0" encoding="utf-8"?> <KPLPLAN> <CODPLAN>KNMPLDMO_PL001</CODPLAN> <CODDEFI>KNMPLDMO</CODDEFI> <CODPROG>KNmPldmo</CODPROG> <VERPROG>12.6.0.5</VERPROG> <MAINFORM>FrmNmPldmo</MAINFORM> <OBSERVACION/> <NOTIFICACION> <NOTIFUSR>sdasd</NOTIFUSR> <NOTIFTIT>sadasdasd</NOTIFTIT> <NOTIFMSG>zczxcz xzczczxc zxczxczxczx </NOTIFMSG> </NOTIFICACION> <PROGRAMACION> <FECHAS> <FECINIC>23/08/2012</FECINIC> <FECFINA>%NOVENC</FECFINA> </FECHAS> <HORA>08:00:00 p.m.</HORA> <FRECUENCIA> <FRECTIP>%MENSU</FRECTIP> <FRECDIA>%ULTDIAMES</FRECDIA> </FRECUENCIA> </PROGRAMACION> <EJECUCION> <PARAMETROS> <PARAMETRO PARTYPE="%CTRL" PARORDN="1" LABEL="Archivo" OWNER="FrmNmPldmo" OBJREF="EdtFileName" OBJTIP="TEdit"> <OPCIONES> <OPCION LABEL="Texto" PROPTIP="" PROPTIP="Text">C:\Garh\NM\Wrk\KNmPldmo.txt</OPCION> </OPCIONES> </PARAMETRO> <PARAMETRO PARTYPE="%CONS" PARORDN="2" LABEL="Consulta" OWNER="DtmNmPldmo" OBJREF="Qry" OBJTIP="TQuery"> <OPCIONES> <OPCION LABEL="SQL" PROPTIP="" PROPTIP="SQL.Text">SELECT * FROM TABLA</OPCION> </OPCIONES> </PARAMETRO> <PARAMETRO PARTYPE="%ACCN" PARORDN="3" LABEL="Aceptar" OWNER="FrmNmPldmo" OBJREF="BitBtnAceptaClick" OBJTIP="TNotifyEvent"/> </PARAMETROS> </EJECUCION> </KPLPLAN> En conclusión porque he dado mucha lora. Sea que quieras generar un XML o no. Lo que te recomiendo es que analices desde dentro de la clase y generes desde allí mismo el resultado que quieres. con una función no tan automatizada y que en determinado momento pueda evaluar tipos de datos internos, variables privadas, etc... Pos si te es de utilidad, hice las pruebas con Delphi 5
__________________
Buena caza y buen remar... http://mivaler.blogspot.com |
#3
|
|||
|
|||
Justamente es lo que tengo que hacer, pero de una Clase X, y generar dicho xml, no conozco que datos pueda tener ese objeto, puede venir el objeto, TPersona, despues el objeto TCualquierCosa, y luego TClientes
Podes darme la idea de como lograste tu xml ??? Tengo este pedazo de codigo pero como leo los datos del objeto para generar el xml... Vuelvo a repetir que tengo que hacer un creador de xml para objeto X,Y o Z
Última edición por elarys fecha: 13-09-2012 a las 22:46:39. |
#4
|
||||
|
||||
El XML que genero lo hago desde dentro del mismo objeto.
Lo hago para poder validar muchas cosas que de seguro desde fuera me seria mas complicado. La verdad no sabria como hacerlo de manera general.
__________________
Buena caza y buen remar... http://mivaler.blogspot.com |
#5
|
|||
|
|||
la idea es hacer algo general, alguien me puede dar la linea si esto sera posible hacerlo y por donde encararlo...
|
#6
|
|||
|
|||
Me contesto solo por si alguno le interesa, asi quedo mi procedimiento
GetPropList, no lee los elementos de clases, entonces tuve que hacerlo con cast o casteo, no se en realidad como se dice... No sabia castear, pero cuando lei un poco por aca y otro poco en google, fue mas facil de lo que parecia
Por las dudas aqui mi unidad Colecciones
Última edición por elarys fecha: 14-09-2012 a las 17:28:31. |
#7
|
||||
|
||||
Me alegro que hallas solucionado tu problema. Pero desde dentro o desde fuera debiste tener el "conocimiento" de que propiedades tiene la colección por dentro.
__________________
Buena caza y buen remar... http://mivaler.blogspot.com |
|
|
Temas Similares | ||||
Tema | Autor | Foro | Respuestas | Último mensaje |
Casteo y Migración | maunix | Varios | 6 | 26-09-2011 16:46:29 |
Crear un TCollection | kloud | C++ Builder | 2 | 04-04-2006 13:52:54 |
Casteo en tiempo de ejecución | moesis | OOP | 4 | 21-07-2005 15:21:56 |
Herencia y Casteo | PeLuCa | OOP | 9 | 05-04-2005 01:29:15 |
TCollection | Igna | OOP | 2 | 24-06-2003 12:24:14 |
|