type question

I have a type defined thusly:

TListOfStringlist = TList<TStringlist>;

I have an XData service defined like this:

function MyFunc( . . . ) : TListOfStringlist;

When I call it via TXDataClient from a VCL test app, I get back what's expected.

When I call it via this in a WEBCore app:

  var comps : TListOfStringList
  . . .
  comps := await( TDbController.Shared.MyFunc( . . . ) );

I get back nothing useful. The value of comps.Count is "undefined" when it should = 3.

I changed the proxy call to return this string instead:

    Result := LResp.Response.ContentAsText;

and the actual response looks like this:

{
    "value": [
        [
            "lineA1",
            "lineA2",
            "lineA3"
        ],
        [
            "lineB1",
            "lineB2",
            "lineB3"
        ],
        [
            "lineC1",
            "lineC2",
            "lineC3"
        ]
    ]
}

This should be a TList of 3 TStringlists, each of which contains 3 strings. But it's not being created correctly.

I guess that from a JSON standpoint, it's an: array of array of string.

The data coming back seems to be the right structure, but the desired object is not being created correctly in the WEB Core environment.

Is this a bug somewhere, or am I just missing something?

Sorry, I forgot this:

function TDbController.MyFunc( . . . ): TListofStringlist;
var
  LResp: TXDataClientResponse;
begin
  LResp := await( Client.RawInvokeAsync( . . . ) );
  if LResp.StatusCode = 200 then
    Result := TListofStringlist( LResp.ResultAsObject[ 'value' ] )
  else
    Result := NIL;
end;

Try always debug/log your code to better understand it. For example, you could do this and let us know what you get in console:

function TDbController.MyFunc( . . . ): TListofStringlist;
var
  LResp: TXDataClientResponse;
begin
  LResp := await( Client.RawInvokeAsync( . . . ) );
  if LResp.StatusCode = 200 then
  begin
    console.log(LResp);
    console.log(LResp.ResultAsObject[ 'value' ]);
    Result := TListofStringlist( LResp.ResultAsObject[ 'value' ] );
  end
  else
    Result := NIL;
end;

Finally try to return a TArray<string> instead of TListofStringlist. You can't cast raw JavaScript objects to Delphi classes:

function TDbController.MyFunc( . . . ): TArray<string>;
var
  LResp: TXDataClientResponse;
begin
  LResp := await( Client.RawInvokeAsync( . . . ) );
  if LResp.StatusCode = 200 then
  begin
    console.log(LResp);
    console.log(LResp.ResultAsObject[ 'value' ]);
    Result := TArray<string>( LResp.ResultAsObject[ 'value' ] );
  end
  else
    Result := NIL;
end;

Thanks.

BTW, it's not a "list of strings". it's a "list of text blocks" and I work with them as blocks. Like paragraphs of text. Each one is independent and they can be reordered.

I changed it to TArrayOfArrayOfString and that works fine.

Also, this was resolved with my other question on the issue of parsing JSON in a WEB Core unit. It straddles the gap between the two (XData and WEB Core) and my confusion was on the other end. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.