This is very strange. Count is a property of TJSONArray (declared in WEBLib.JSON.pas) and GetCount a function.
Are you 100% sure that at the moment of access, FProducts is effectively an instance of the type TJSONArray?
TSMXUtilsSvc = Class
Private
FClient: TXDataWebClient;
FProducts: TJSONArray;
Protected
Public
Constructor Create; Reintroduce;
Destructor Destroy; Override;
Function ProductList: TJSONArray;
Procedure LoadProducts;
Function ProductName(Const Id: Integer): String;
End;
and the loadings is done
procedure TSMXUtilsSvc.LoadProducts;
Procedure OnSuccess(Response: TXDataClientResponse);
Begin
FProducts := TJSONArray(Response.Result);
End;
Procedure OnError(Error: TXDataClientError);
Begin
//AOnError(Format('%s: %s', [Error.ErrorCode, Error.ErrorMessage]));
End;
Begin
if Assigned(FProducts) then
begin
FProducts.Free;
FProducts := Nil;
end;
FClient.RawInvoke('ISMXUtilsService.ProductList', [], @OnSuccess, @OnError);
end;
The issue is in
function TSMXUtilsSvc.ProductName(const Id: Integer): String;
var I: Integer;
lProduct: TJSONObject;
begin
Result := 'unknown product';
for I := 0 to FProducts.Count - 1 do
begin
lProduct := FProducts[I] as TJSONObject;
if lProduct.GetJSONValue('Id').ToInteger = Id then
begin
Result := lProduct.GetJSONValue('Name');
Exit;
end;
end;
end;
Looking at FProducts at that point in the debugger shows:
Just to confirm switching to TJSArray as suggested by @Czech_Tomasz did the trick. I just thought that as the XData Server returned a TJSONArray taht's what should be used on the client side.