简体   繁体   中英

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)

[DCC Error] superobject.pas(601): E2154 Type 'TSuperTableString' needs finalization - not allowed in variant record

The following code works in windows without any issue but not when I change to android platform :

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. You need the cross platform fork 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. For the desktop compilers classes are unmanaged. For the mobile compilers, classes are managed types, managed using 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.

However, as I said yesterday in your previous question, the built in parser in System.JSON is perfectly capable of parsing your JSON. There is no need for you to switch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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