Delphi 7: Access Violation - TByteDynArray Problem

I am new to Delphi and have to encode a SOAP client. The WSDL import generates this code (which I obviously cannot change, since I obviously have to respect the server side)

  DataPart            = class;             
  Message             = class;             
  eMessage            = class;             

  eventType = ( send, delete, etc );

  DataPart = class(TRemotable)
  private
    FhasData: Boolean;
    Fdata: TByteDynArray;
  published
    property hasData: Boolean read FhasData write FhasData;
    property data: TByteDynArray read Fdata write Fdata;
  end;
  Message = class(TRemotable)
  private
    FMessageID: Int64;
    Ftimestamp: TXSDateTime;
    Fevent: eventType;
    FmagicNumber: WideString;
    FDataPart: DataPart;
  published
    property MessageID: Int64 read FMessageID write FMessageID;
    property timestamp: TXSDateTime read Ftimestamp write Ftimestamp;
    property event: eventType read Fevent write Fevent;
    property magicNumber: WideString read FmagicNumber write FmagicNumber;
    property DataPart: DataPart read FDataPart write FDataPart;
  end;

  eMessage = class(TRemotable)
  private
    FencryptedMessage: TByteDynArray;
    Fdata: DataPart;
  published
    property encryptedMessage: TByteDynArray read FencryptedMessage write FencryptedMessage;
    property data: DataPart read Fdata write Fdata;
  end;

  MyApplicationPortType = interface(IInvokable)
  ['{99767D33-6B4A-7547-4DAC-0608095CAC70}']

    function  sendMessage(const encryptedMessage: TByteDynArray; const data: DataPart): WideString; stdcall;
  end;

Can someone program me an example with dummy values ​​that will call sendMessage () and not cause an access violation? I really don't know how to handle TByteDynArray


[Change] in accordance with the request, here is my code, BUT - disclaimer - I had to cheat (decrease) it many times before publishing, so it can not be compiled. Both message sets sendMessage () are not null.

  var theMessageArray: TByteDynArray;
      theResult : WideString;
      messageData : TByteDynArray;
      i : Integer;
begin
  theMessage.messageID := theMessage.messageID + 1;
  theMessage.timestamp := TXSDateTime.Create();
  theMessage.timestamp.AsDateTime := Now();
  theMessage.event := delete;
  theMessage.magicNumber  := 'magic # ' + IntToStr(theMessage.messageID);

  SetLength(messageData, 1);
  messageData[0] := 0;

  theMessage.dataPart.hasData := True;
  messageData := theMessage.dataPart.messageData;

  SetLength(messageData, $1000 * dataSize);

  for i := 0 to $1000 * dataSize - 1 do
        messageData[i] := i and $FF;

  theMessage.DataPart.messageData := messageData;

  theMessageArray := TByteDynArray(theMessage);
  theResult := (HTTPRIO1 as MyApplicationPortType).sendMessage(theMessageArray, theMessage.dataPart);
+3
source share
1 answer

. ? {$ R +}

, , , / .

SetLength TByteDynArray :

SetLength(Fdata, MyDesiredLengthWhichIsGreaterThanZero):

, , :

  property data: TByteDynArray read Fdata write Fdata;

, , , , -, . (: ).

TRemotable, Rob, , " " (TByteDynArray), , , TByteDynArray ( ).

, "string", TBytes. , TBytes, , SOAP-, - WSDL--. , , , .

.

, SOAP-, , . , , "uh-oh, why do you do the Cast here", Rob. , , , , , TRemotable.

, :

  procedure TestMe( whatever:TWhatever );
  var 
    FData:TByteDynArray;
  begin
     SetLength(FData,2); 
     FData[0] := 10; 
     FData[1] := 20;
     sendMessage(FData, whatever);
  end;
+3

Source: https://habr.com/ru/post/1752624/


All Articles