Ver Mensaje Individual
  #13  
Antiguo 09-04-2015
doctorhd doctorhd is offline
Miembro
NULL
 
Registrado: abr 2013
Posts: 48
Reputación: 0
doctorhd Va por buen camino
Bueno finalmente mi diseño quedo de la siguiente forma:
Código Delphi [-]

TEnumTypeData = (tyNone,tyCurrency, tyBoolean, tyDate, tyDateTime, tyFloat, tyInteger, tyString, tyExpandString, tyTime, tyBinaryData);

TClaveValor = record
      private
        FClave:string;
        FValueDefault:Variant;
        FValue:Variant;
        FTipo:TEnumTypeData;
        procedure SetClave(const Value:string);
        procedure SetValueDefault(const Value:variant);
        procedure SetValue(const Value:variant);
        procedure SetTipo(const Value:TEnumTypeData);
      public
        property Clave: string read FClave write SetClave;
        property ValueDefault: Variant read FValueDefault write SetValueDefault;
        property Value:Variant read FValue write SetValue;
        property Tipo: TEnumTypeData read FTipo write SetTipo;
    end;

  procedure TClaveValor.SetClave(const Value:string);
  begin
    FClave:=Value;
  end;

  procedure TClaveValor.SetValueDefault(const Value:variant);
  begin
    FValueDefault:=Value;
  end;

  procedure TClaveValor.SetValue(const Value:variant);
  begin
    FValue:=Value;
  end;

  procedure TClaveValor.SetTipo(const Value:TEnumTypeData);
  begin
    FTipo:=Value;
  end;

 type PClaveValor = ^TClaveValor;{Puntero a TClaveValor }

 type
    TConfigBDRegistro = class
    private
      FTipoServer:TClaveValor;
      FNameServer:TClaveValor;
      FRuta:TClaveValor;
      FProComunicacion:TClaveValor;
      FRutaVendorLib:TClaveValor;
      FListCampos:array of PClaveValor;
      function GetCampo(const Index: Integer): PClaveValor;
      procedure SetCampo(const Index: Integer; const Value: PClaveValor);
      function GetNCampos:Integer;
    public
      constructor Create;
      property TipoServer:TClaveValor read FTipoServer write FTipoServer;
      property NameServer:TClaveValor read FNameServer write FNameServer;
      property Ruta:TClaveValor read FRuta write FRuta;
      property ProComunicacion:TClaveValor read FProComunicacion write FProComunicacion;
      property RutaVendorLib:TClaveValor read FRutaVendorLib write FRutaVendorLib;
      property ListCampos[const Index: Integer]:PClaveValor read GetCampo write SetCampo;
      property NCampos:Integer read GetNCampos;
    end;

  constructor TConfigBDRegistro.Create;
  begin
    Setlength(FListCampos,5);{Dimencionamos el tamaño de la lista de campos}
    FListCampos[0]:=@FTipoServer;
    FListCampos[1]:=@FNameServer;
    FListCampos[2]:=@FRuta;
    FListCampos[3]:=@FProComunicacion;
    FListCampos[4]:=@FRutaVendorLib;
  end;{constructor}

  function TConfigBDRegistro.GetCampo(const Index:Integer):PClaveValor;
  begin
    Result:=FListCampos[Index];
  end;{function}

  procedure TConfigBDRegistro.SetCampo(const Index:Integer; const Value:PClaveValor);
  begin
    FListCampos[Index]:=Value;
  end;{function}

  function TConfigBDRegistro.GetNCampos:Integer;
  begin
    Result:=High(FListCampos);
  end;{function}

Para ser llamado asi:

Código Delphi [-]
  ....
   vFin:=ConfigBDRegistro.NCampos;
   {recorremos la lista de campos}
   for vIndice:=0 to vFin do begin
     ListCampos[vIndice].Value:='un Dato';{Funciona}
   end;{for}
  ....

Un comentario acerca de lo dicho por mamcx
Cita:
1- Estas usando un record como si fuera una clase
Si, pero el lenguaje lo permite y lo implementa como una opción, por tanto porque no utilizarlo...

Creo que mamcx tiene razón en varios de los comentarios que hace, referente a simplificar el diseño utilizando solo record y funciones, ahora la pregunta es cuando programar O.O y cuando programar procedimientalmente... En mi caso mi aprendizaje fue enfocado a este ultimo, pero he ido cambiando de paradigma, por las enormes ventajas que representa programar O.O. herencia, encapsulacion, etc... Quizas utilizar lo mejor de ambos modelos...????

Saludos...
Responder Con Cita