Difficulty creating a property for a CLASS

0

I'm using DELPHI 7 trying to create a class with the following structure

Type
  Tclasse_Envio_JSON =  class(TThread)
  private  
    fCampos: Array of Variant;
    fIdade : Integer;
    fNome  : String[40];
    function Get_Idade: Integer;
    procedure Set_Idade(const Value: Integer);    
    function Get_Campos: array of Variant;
    procedure Set_Campos(const Value: array of Variant);         
  public
    Property Idade : Integer read Get_Idade write Set_Idade;    
    Property Campos : Array of Variant read Get_Campos write Set_Campos;
  protected
    procedure Execute; Override;      
end;

I'm having difficulty implementing the:

property Campos
function Get_Campos 
procedure Set_Campos

The idea of using it would be

variavelA       := TClasse_Envio_JSon.Create;
VariavelA.Campo := ['CampoA','CampoB','CampoC'];
VariavelA.Valor :=['Valor_CampoA','Valor_CampoB','Valor_CampoC'];

How do I use the ARRAY Of VARIANT in this situation ???
Or if any of you have any other idea I can get the same result .. I'm all EYES :)
It could do something with bounded STRINGS and search them, but the bid with Array of Variant is much cleaner.
We use a lot of Array of Variant in passing parameters in function. Inclusive This class I am trying to implement is to substitute a function.

Function Envia_Json(pCampos : Array of Variant; pValores : Array of Variant) : Boolean;
Var A : Integer;
begin
  For A:= 0 to High(pCampos) do
      begin
         ETC..ETC..
      end;
  ETC.. ETC..
end;

Using Function Envia_Json ..:

  If Envia_Json(['CampoA','CampoB'],['ValorAA','VAlorA','ValorB','ValorC','Valord']) then
     begin
     end;

I hope to have demonstrated my doubt and need clearly ..
If any of you find my lines confusing, please write to me and I'll try to explain it better.

    
asked by anonymous 25.04.2018 / 13:02

1 answer

1

I already think of something simpler to solve, both sending and receiving ...

For upload imagine a List (can be a TStringList), key and value ...

To receive, you would use:

var
  vJson : TJSONObject;
begin
  vJson := TJSONObject.Create;  

  for i := 0 to Pred(xList.Count) do
  begin
    vJson.AddPair(xListaCHAVE, xListaVALOR);
  end;

  Result := vJson.ToString;
  vJson.Free;
end;

Note: For TJSONObject declare Data.DBXJSON for old versions, for new ones System.Json

    
25.04.2018 / 13:16