简体   繁体   English

在Delphi XE7 Android Target中使用SuperObject时出错

[英]Error in using SuperObject in Delphi xe7 android Target

The following error occurs when I debug my project by changing the Target platform to Android (SDK.22.3.32 bit) 通过将目标平台更改为Android(SDK.22.3.32位)来调试项目时,会发生以下错误

[DCC Error] superobject.pas(601): E2154 Type 'TSuperTableString' needs finalization - not allowed in variant record [DCC错误] superobject.pas(601):E2154类型'TSuperTableString'需要完成-变体记录中不允许

The following code works in windows without any issue but not when I change to android platform : 下面的代码在Windows中可以正常工作,但是当我更改为android平台时却不能:

procedure TForm1.Button1Click(Sender: TObject);
var jv: TJSONValue;
    jo: TJSONObject;
    jp: TJSONPair;
    ja: TJSONArray;
    i: integer;
    j: integer;
    strString,strValue,strArray:string;
begin

    ListBox1.Clear;


    RESTRequest1.Execute;

    jv:=RESTResponse1.JSONValue;


    jo:= TJSONObject.ParseJSONValue(jv.ToString) as TJSONObject;

    try
      for i := 0 to jo.Count - 1 do
      begin
        jp := jo.Pairs[i];

        if jp.JsonValue is TJSONArray then
        begin
            ja := jp.JsonValue as TJSONArray;
            for j := 0 to ja.Count -1 do
            begin
              PrintNamesAndValues(ja.Items[j].ToString);
            end;
        end;

      end;
    finally
      jo.Free;
    end;


end;

** **

procedure TForm1.PrintNamesAndValues(prmJson:string);
var O:ISuperObject ;
    name,email,tod:string;
begin
    O := SO(prmJson);
    name := O.S['name'];
    tod := O.S['email'];

    ListBox1.Items.Add(name+'('+email+')');
end;

Any idea what will be the solution ? 您知道解决方案是什么吗? please help. 请帮忙。

Thanks. 谢谢。 /koul /考尔

Superobject doesn't support the mobile platforms. Superobject不支持移动平台。 You need the cross platform fork x-superobject: https://code.google.com/p/x-superobject/ 您需要跨平台前叉x-superobject: https : //code.google.com/p/x-superobject/

The compiler error you report is because of this: 您报告的编译器错误是由于以下原因:

FO: record
  case TSuperType of
    stBoolean: (c_boolean: boolean);
    stDouble: (c_double: double);
    stCurrency: (c_currency: Currency);
    stInt: (c_int: SuperInt);
    stObject: (c_object: TSuperTableString);
    stArray: (c_array: TSuperArray);
{$IFDEF SUPER_METHOD}
    stMethod: (c_method: TSuperMethod);
{$ENDIF}
  end;
{.$ifend}

Now, TSuperTableString is a class. 现在, TSuperTableString是一个类。 For the desktop compilers classes are unmanaged. 对于桌面编译器,类是不受管的。 For the mobile compilers, classes are managed types, managed using ARC. 对于移动编译器,类是使用ARC管理的托管类型。 And managed types cannot appear in variant records. 并且托管类型不能出现在变体记录中。 Hence the error only for mobile compilers. 因此,该错误仅适用于移动编译器。

I'm sure there are other reasons why superobject doesn't support mobile compilers. 我敢肯定还有其他原因为什么超对象不支持移动编译器。 So, you need to use x-superobject instead. 因此,您需要使用x-superobject。

However, as I said yesterday in your previous question, the built in parser in System.JSON is perfectly capable of parsing your JSON. 但是,正如我昨天在上一个问题中所说的那样, System.JSON的内置解析器完全能够解析您的JSON。 There is no need for you to switch. 无需您切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM