Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 30-07-2012
elarys elarys is offline
Miembro
 
Registrado: abr 2007
Posts: 94
Poder: 20
elarys Va por buen camino
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.

Código Delphi [-]
//La llamada a la funcion seria algo como
GetPropertyList(Producto, tkProperties, 0);

//Y aca dicha funcion
procedure GetPropertyList(Obj: TObject; Filter: TTypeKinds; Counter: integer);
var
  Names, Value, Tipo: string;
  PInfo: PPropInfo;
  PropList: PPropList;
  Count, i, j: integer;
  Ob: TObject;
begin
  //Aqui obtengo la lista de propiedades del objeto
  Count := GetPropList(Obj.ClassInfo, Filter, nil);
  GetMem(PropList, Count * SizeOf(PPropInfo));
  GetPropList(Obj.ClassInfo, Filter, PropList);
  //---

  //Luego las recorro y obtengo
  for i := 0 to Count -1 do
  begin
    Value := GetPropValue(Obj, Proplist[i].Name); //Valor de cada propiedad
    PInfo := GetPropInfo(Obj, Proplist[i].Name); //info para obtener tipo de propiedad luego
    Names := UpperCase(Proplist[i].Name); //Nombre de cada propiedad

    //Aqui segun la informacion de la propiedad obtengo el tipo
    //Añadi todos los casos posibles
    //En el caso de que la propiedad sea TDateTime claro con un formatdatetime se soluciona
    //pero el tipo que me devuelve cuando es tdatetime es float... entonces cuando me lee FPrecio
    //lo transformaria tambien con formatdatetime siendo que este si es float y no hay que modificarlo.
    //Estoy viendo que puedo hacer al respecto

    if PInfo <> nil then
    begin
      case PInfo^.PropType^.Kind of
        tkUnknown: Tipo := 'Unknown';
        tkInteger: Tipo := 'Integer';
        tkChar: Tipo := 'Char';
        tkEnumeration: Tipo := 'Enumeration';
        tkFloat: Tipo := 'Float';
        tkString: Tipo := 'String';
        tkSet: Tipo := 'Set';
        tkClass: Tipo := 'Class';
        tkMethod: Tipo := 'Method';
        tkWChar: Tipo := 'WChar';
        tkLString: Tipo := 'LString';
        tkWString: Tipo := 'WString';
        tkVariant: Tipo := 'Variant';
        tkArray: Tipo := 'Array';
        tkRecord: Tipo := 'Record';
        tkInterface: Tipo := 'Interface';
        tkInt64: Tipo := 'Int64';
        tkDynArray: Tipo := 'DynArray';
      end;
    end;

    //Si es de tipo clase, llamo nuevamente mi procedimiento de forma recursiva
    if Tipo = 'Class' then
    begin
      j := High(xmlArray) + 1;
      SetLength(xmlArray, j + 1);
      SetLength(xmlArray[j], 1);
      xmlArray[j][0] := '<' + Names + '>';

      Ob := GetObjectProp(Obj, Proplist[i].Name);
      GetPropertyList(Ob, tkProperties, Counter + 1);

      j := High(xmlArray) + 1;
      SetLength(xmlArray, j + 1);
      SetLength(xmlArray[j], 1);
      xmlArray[j][0] := + '< /' + Names + '>';
      //Esta parte '< /' debe ir sin espacios pero las etiquetas delphi de la pagina me las borra
      //si le quito el espacio, si no se quita el espacio al querer leer el xml da error
    end
    else
    begin
      //Por ahora si es de otro tipo solo lo cargo en un array
      //como si lo tuviera que escribir en xml
      j := High(xmlArray) + 1;
      SetLength(xmlArray, j + 1);
      SetLength(xmlArray[j], 1);
      xmlArray[j][0] := '<' + Names + '>' + Value + '< /' + Names + '>';
    end;
  end;
end;

Última edición por elarys fecha: 30-07-2012 a las 21:08:12.
Responder Con Cita
  #2  
Antiguo 30-07-2012
elarys elarys is offline
Miembro
 
Registrado: abr 2007
Posts: 94
Poder: 20
elarys Va por buen camino
Código Delphi [-]
{
En el procedimiento anterior el resultado lo pasaba a un array dinamico porque pensaba
que me hacian falta mas lineas, en este el resultado se carga en un stringlist y me ahorro
como 5 lineas de codigo jejeje, ver List.Add
}

procedure GetPropertyList(Obj: TObject; Filter: TTypeKinds; List: TStringList; Counter: integer);
var
  Names, Value, Tipo: string;
  PInfo: PPropInfo;
  PropList: PPropList;
  Count, i, j: integer;
  Ob: TObject;
begin
  Count := GetPropList(Obj.ClassInfo, Filter, nil);
  GetMem(PropList, Count * SizeOf(PPropInfo));
  GetPropList(Obj.ClassInfo, Filter, PropList);

  for i := 0 to Count -1 do
  begin
    Value := GetPropValue(Obj, Proplist[i].Name);
    PInfo := GetPropInfo(Obj, Proplist[i].Name);
    Names := UpperCase(Proplist[i].Name);

    if PInfo <> nil then
    begin
      case PInfo^.PropType^.Kind of
        tkUnknown: Tipo := 'Unknown';
        tkInteger: Tipo := 'Integer';
        tkChar: Tipo := 'Char';
        tkEnumeration: Tipo := 'Enumeration';
        tkFloat: Tipo := 'Float';
        tkString: Tipo := 'String';
        tkSet: Tipo := 'Set';
        tkClass: Tipo := 'Class';
        tkMethod: Tipo := 'Method';
        tkWChar: Tipo := 'WChar';
        tkLString: Tipo := 'LString';
        tkWString: Tipo := 'WString';
        tkVariant: Tipo := 'Variant';
        tkArray: Tipo := 'Array';
        tkRecord: Tipo := 'Record';
        tkInterface: Tipo := 'Interface';
        tkInt64: Tipo := 'Int64';
        tkDynArray: Tipo := 'DynArray';
      end;
    end;

    if Tipo = 'Class' then
    begin
      List.Add('<' + Names + '>');
      Ob := GetObjectProp(Obj, Proplist[i].Name);
      GetPropertyList(Ob, tkProperties, List, Counter + 1);
      List.Add('< /' + Names + '>');
    end
    else
    begin
      List.Add('<' + Names + '>' + Value + '< /' + Names + '>');
    end;
  end;
end;
Responder Con Cita
  #3  
Antiguo 31-07-2012
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is online now
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 19.437
Poder: 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
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.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

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


La franja horaria es GMT +2. Ahora son las 13:50:45.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi