Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Problema al asignar valor a array (https://www.clubdelphi.com/foros/showthread.php?t=72648)

ferjavrec2 03-03-2011 19:36:19

Problema al asignar valor a array
 
Hola buenas tardes, les quiero pedir si me pueden ayudar con este error que tengo ya que no lo he podido soluccionar aun. Estoy haciendo un sistema para autorizar factura electronicas y al querer asignar un valor al array me sale un error "Access violation at address 00531246 in module 'Project1.exe'. Read of address 00000000"

aca dejo la forma como cargo un dato al array:
Código Delphi [-]
var
 prueba: ArrayOfFEDetalleRequest;
begin
 prueba[0].tipo_doc := 80;

end;


Y aca dejo parte del WebService:
Código Delphi [-]
ArrayOfFEDetalleRequest = array of FEDetalleRequest;


  // ************************************************************************ //
  // XML       : FERequest, global, 
  // Namespace :
  // ************************************************************************ //
  FERequest = class(TRemotable)
  private
    FFecr: FECabeceraRequest;
    FFecr_Specified: boolean;
    FFedr: ArrayOfFEDetalleRequest;
    FFedr_Specified: boolean;
    procedure SetFecr(Index: Integer; const AFECabeceraRequest: FECabeceraRequest);
    function  Fecr_Specified(Index: Integer): boolean;
    procedure SetFedr(Index: Integer; const AArrayOfFEDetalleRequest: ArrayOfFEDetalleRequest);
    function  Fedr_Specified(Index: Integer): boolean;
  public
    destructor Destroy; override;
  published
    property Fecr: FECabeceraRequest        Index (IS_OPTN) read FFecr write SetFecr stored Fecr_Specified;
    property Fedr: ArrayOfFEDetalleRequest  Index (IS_OPTN) read FFedr write SetFedr stored Fedr_Specified;
  end;



  // ************************************************************************ //
  // XML       : FEDetalleRequest, global, 
  // Namespace :
  // ************************************************************************ //
  FEDetalleRequest = class(TRemotable)
  private
    Ftipo_doc: Integer;
    Fnro_doc: Int64;
    Ftipo_cbte: Integer;
    Fpunto_vta: Integer;
    Fcbt_desde: Int64;
    Fcbt_hasta: Int64;
    Fimp_total: Double;
    Fimp_tot_conc: Double;
    Fimp_neto: Double;
    Fimpto_liq: Double;
    Fimpto_liq_rni: Double;
    Fimp_op_ex: Double;
    Ffecha_cbte: string;
    Ffecha_cbte_Specified: boolean;
    Ffecha_serv_desde: string;
    Ffecha_serv_desde_Specified: boolean;
    Ffecha_serv_hasta: string;
    Ffecha_serv_hasta_Specified: boolean;
    Ffecha_venc_pago: string;
    Ffecha_venc_pago_Specified: boolean;
    procedure Setfecha_cbte(Index: Integer; const Astring: string);
    function  fecha_cbte_Specified(Index: Integer): boolean;
    procedure Setfecha_serv_desde(Index: Integer; const Astring: string);
    function  fecha_serv_desde_Specified(Index: Integer): boolean;
    procedure Setfecha_serv_hasta(Index: Integer; const Astring: string);
    function  fecha_serv_hasta_Specified(Index: Integer): boolean;
    procedure Setfecha_venc_pago(Index: Integer; const Astring: string);
    function  fecha_venc_pago_Specified(Index: Integer): boolean;
  published
    property tipo_doc:         Integer  read Ftipo_doc write Ftipo_doc;
    property nro_doc:          Int64    read Fnro_doc write Fnro_doc;
    property tipo_cbte:        Integer  read Ftipo_cbte write Ftipo_cbte;
    property punto_vta:        Integer  read Fpunto_vta write Fpunto_vta;
    property cbt_desde:        Int64    read Fcbt_desde write Fcbt_desde;
    property cbt_hasta:        Int64    read Fcbt_hasta write Fcbt_hasta;
    property imp_total:        Double   read Fimp_total write Fimp_total;
    property imp_tot_conc:     Double   read Fimp_tot_conc write Fimp_tot_conc;
    property imp_neto:         Double   read Fimp_neto write Fimp_neto;
    property impto_liq:        Double   read Fimpto_liq write Fimpto_liq;
    property impto_liq_rni:    Double   read Fimpto_liq_rni write Fimpto_liq_rni;
    property imp_op_ex:        Double   read Fimp_op_ex write Fimp_op_ex;
    property fecha_cbte:       string   Index (IS_OPTN) read Ffecha_cbte write Setfecha_cbte stored fecha_cbte_Specified;
    property fecha_serv_desde: string   Index (IS_OPTN) read Ffecha_serv_desde write Setfecha_serv_desde stored fecha_serv_desde_Specified;
    property fecha_serv_hasta: string   Index (IS_OPTN) read Ffecha_serv_hasta write Setfecha_serv_hasta stored fecha_serv_hasta_Specified;
    property fecha_venc_pago:  string   Index (IS_OPTN) read Ffecha_venc_pago write Setfecha_venc_pago stored fecha_venc_pago_Specified;
  end;

Bueno desde ya muchas gracias por su tiempo.
saludos

Crandel 04-03-2011 04:00:48

prueba es del tipo ArrayOfFEDetalleRequest que a su vez es un array dinamico, por lo que debes definir un tamaño a ese vector antes de poder asignarle elementos.

Por ejemplo pon esta linea antes de la asignación:

Código Delphi [-]
SetLength(prueba, 1);
.

ferjavrec2 04-03-2011 18:11:46

Mira en realidad yo me confundi cuando declaro el array, esta es la forma que seria, en la cual me genera el error. De todas formas probe con SetLength y sigue haciendo el mismo error:

Código Delphi [-]
var
 prueba: FERequest;
begin
 prueba := FERequest.Create;
 prueba.Fedr[0].tipo_doc := 80;
end;

Bueno, muchas gracias a todos.
saludos

Crandel 04-03-2011 18:42:57

Te quedaría asi:

Código Delphi [-]
var
 prueba: FERequest;
begin
 prueba := FERequest.Create;
 SetLength(prueba.FFedr,1);
 prueba.FFedr[0] := FEDetalleRequest.Create;
 prueba.FFedr[0].Ftipo_doc := 80;
end;

primero SetLength le da un tamaño a tu vector dinamico y segundo como cada elemento de ese vector es puntero a un objeto debes crear el objeto antes.

Con esto ya no deberias tener problemas

ferjavrec2 04-03-2011 19:06:19

Muchas gracias por tu respuesta, mira te cuento que me da error en la linea SetLength(prueba.Fedr,1);:

[DCC Error] Unit1.pas(113): E2197 Constant object cannot be passed as var parameter

muchas gracias

Crandel 04-03-2011 20:50:52

nop, no puedes darle el tamaño a esa propiedad desde afuera, deberas agregar un metodo para eso

ferjavrec2 06-03-2011 22:14:33

ok, muchas gracias, ya lo pude soluccionar.
saludos


La franja horaria es GMT +2. Ahora son las 22:49:07.

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