在Delphi上启动SOAP数组

时间:2012-12-17 15:36:32

标签: arrays delphi soap

我正在尝试初始化或创建一个soap调用数组:

Array_Of_ProductIdentifierClinicalType = array of ProductIdentifierClinicalType;

这是我尝试初始化它的方式:

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

当我运行应用程序时,我收到此错误:地址访问冲突...

enter image description here

问题是:如何初始化这个肥皂调用?

感谢您的时间!!!! 您可以在http://axelcarreras.dyndns.biz:3434/WSAlchemy.wsdl

上执行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;*

1 个答案:

答案 0 :(得分: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动态数组的理解很差。我建议你咨询documentation