0

I am trying to initialize or create an array of a soap call:

Array_Of_ProductIdentifierClinicalType = array of ProductIdentifierClinicalType;

This is the way that I am trying to initialize it:

Product[0].IdentifierType := Array_Of_ProductIdentifierClinicalType.Create();

When I run the application I get this error: Access Violation at address...

enter image description here

The question would be: How to initialize this soap call??

Thank you for your time!!!! You can do a WSDL import on: http://axelcarreras.dyndns.biz:3434/WSAlchemy.wsdl

procedure TFrmMain.Button16Click(Sender: TObject);
Var
  ExcludeExpiradas: String;
  Serv: AlchemyServiceSoap;
  req: AlchemyClinical;
  element: AlchemyClinicalRequest;
  Prescribed: PrescribedType;
  //Prescribing: Prescribing
  Prescribing: PrescribedType;
  alc: AlchemyIdentifierType;
  D: TXSDate;
  Counter: Integer;
  ProductStr: AlchemyIdentifierClinicalType;


begin

  With DM do
  begin
    ExcludeExpiradas := ' and (' + chr(39) +  DateToStr(Date) + chr(39) + ' < (FECHARECETA + 180)) ';
    CDSRx_Procesadas.Close;
    CDSRx_Procesadas.CommandText := 'SELECT * ' +
    ' FROM RX_PROCESADAS WHERE ' +
    ' (NUMERORECETA IS NOT NULL AND CANTIDAD_DISPONIBLE > 0)' +
     ExcludeExpiradas +
    ' and NumeroCliente = ' + CDSPacientesNumeroCliente.asString +
    ' Order by NumeroReceta';
    //ShowMessage(CDSRx_Procesadas.CommandText);
    CDSRx_Procesadas.Open;

    ProductStr := AlchemyIdentifierClinicalType.Create;
    With ProductStr do
    begin
      Identifier := 1;
    end;

    element := AlchemyClinicalRequest.Create;
    //Prescribed := PrescribedType.Create;
    With element do
    begin
      With Prescribed do
      begin
        Counter := 0;
        while not CDSRx_Procesadas.eof do
        begin
          Product := Array_Of_ProductIdentifierClinicalType.Create();
          With Product[0] do
          begin
            IdentifierType := ProductIdentifierTypeEnum.NDC9;
            Identifier := Copy(DM.CDSInventarioNDC.Value, 1, 9);
          end;
          Counter := Counter + 1;
          CDSRx_Procesadas.Next;
        end;
      end;
      With Prescribing do
      begin
        Counter := 0;
        Product[0].IdentifierType := ProductIdentifierTypeEnum.AlchemyProductID;
        Product[0].Identifier := Copy(DM.CDSInventarioNDC.Value, 1, 9);
        Counter := Counter + 1;
      end;
      With PatientDemographics do
      begin
        while not CDSAlergies.Eof do
        begin
          Allergy.AllergySubstanceClass[0].Identifier := CDSAlergiesNOALERGIA.Value;
          CDSAlergies.Next;
        end;
        if CDSPacientesSEXO.Value = 1 then
          Gender := GenderTypeEnum.Male
        else
          Gender := GenderTypeEnum.Female;

        D := TXSDate.Create;
        D.AsDate := CDSPacientesFECHANACIMIENTO.AsDateTime;
        DateOfBirth := D;
      end;
      With RequestedOperations do
      begin
        DrugToDrug := True;
        //DuplicateTherapy
        Allergy := True;

        With WarningLabels do
        begin
          Request := True;
          LanguageCode := 'en-US';
          MaxLines := 5;
          CharsPerLine := 24;
        end;
        With DoseScreening do
        begin
          Request := True;
        end;
        AdverseReactions.Request := True;
      end;
      IgnorePrescribed := False;
      IncludeConsumerNotes := True;
      IncludeProfessionalNotes := True;
    end;
  end;
end;*
4

1 回答 1

2

假设问题中的这行代码是准确的:

Array_Of_ProductIdentifierClinicalType = array of ProductIdentifierClinicalType;

那么问题就在这里:

Product := Array_Of_ProductIdentifierClinicalType.Create();

这是一个动态数组构造函数。它创建一个长度等于构造函数参数数量的动态数组。然后将数组的每个元素依次分配给传递的参数。

考虑一个使用TBytes = array of Byte.

Bytes := TBytes.Create(1, 2, 3);

这初始化Bytes为一个长度为 3 且具有值 1、2 和 3 的数组。

现在,让我们再次查看您的代码。这初始化Product为长度为 0 的数组。因此,当您访问Product[0]该数组时,会导致运行时错误,因为数组索引超出范围。

要解决此问题,您需要确保数组已初始化为具有足够的元素。一种选择当然是使用动态数组构造函数。另一个是使用SetLength. 我怀疑你对 Delphi 的动态数组的理解很差。我建议您查阅文档

于 2012-12-17T21:39:16.303 回答