0

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

koul
  • 431
  • 2
  • 10
  • 20
  • 2
    I cannot understand which parser you are using. You appear to be using two different parsers. There's a different version of superobject for mobile platforms. The built in parser works on mobile platforms, but from your previous question it seems that you don't want to use the built in parser. – David Heffernan Feb 13 '15 at 11:46
  • please submit an example – koul Feb 13 '15 at 11:50
  • I don't understand that comment at all. An example of what? Based on your previous question it seems like you have no desire to understand the code, or JSON, but you just want somebody else to write code for you. I've no interest in writing code for you. I do enjoy helping people learn and gain understanding. – David Heffernan Feb 13 '15 at 11:52
  • You probably want this: https://code.google.com/p/x-superobject/ – David Heffernan Feb 13 '15 at 11:57
  • David , I do not understand your such behavior, if you don't want to help or you don't have any interest to answer on it , why you are loosing your time, go and have a look on other interesting question.It seems you don't understand . – koul Feb 13 '15 at 12:29
  • You misunderstand. I do want to help. But I want to help you learn. Writing the code for you isn't helping. I think I understand the question too. Your System.JSON code doesn't work because it assumes that the root is an object, when in fact it is an array. The superobject code doesn't work on mobile because superobject is not supported on mobile. So yes, I understand the problem. The question is, do you want to understand, or do you just want to acquire code that works? – David Heffernan Feb 13 '15 at 12:31
  • Who told you to write the code for me ? I m facing a problem that I submitted to people who are willing to help by giving idea or direction or something like that. note I m not a guru , Im just starting to learn Delphi.Please don't waste your time here , i told you go away look after an intelligent question, here I just asking a stupid ones – koul Feb 13 '15 at 12:35
  • You said, "please submit an example". I assumed that meant that you wanted us to write code for you. What did you mean? Did you read any of what I wrote above about superobject? Not being supported on mobile? Did you follow the link I gave you? It seemed to me at your past question that you did not want to learn. Instead of grasping the issue with your code, and why it didn't match JSON, you decided to use a different parser! – David Heffernan Feb 13 '15 at 12:36
  • No at all, you were talking about parser for mobile platforms wich I never heard about it, that was my purpose. – koul Feb 13 '15 at 12:38
  • I'm happy to try to help you learn if that's what you want. You already have all the information you need in the comments above, I think. – David Heffernan Feb 13 '15 at 12:39
  • the link that you submit is the one that I used on my code, – koul Feb 13 '15 at 12:39
  • You said you were using superobject. I gave you a link to x-superobject. Also, most of your code uses System.JSON. – David Heffernan Feb 13 '15 at 12:40
  • One thing that is somewhat frustrating is that `jo:= TJSONObject.ParseJSONValue(jv.ToString) as TJSONObject;` is wrong because your JSON (which we cannot see but have to assume is the same as in your previous question) has an array at the root. I explained this to you yesterday. And yet the code is still here. Or is your root now an object rather than an array? It's frustrating when it seems like people don't listen. We like people that ask, but not when the same questions get asked repeatedly. Do you see? – David Heffernan Feb 13 '15 at 12:45
  • have a look at the second procedure , I m using superObject over there – koul Feb 13 '15 at 12:46
  • Yes, I can see that. So I'm confused why there are two parsers. You want to use both? If we aren't meant to look at the first code, why is it here? And I still don't know whether you use superobject or x-superobject. Do you know the difference? If not, please ask me. – David Heffernan Feb 13 '15 at 12:50
  • As much as anything I'm frustrated by the guy that said, "switch to superobject". Superobject is very good. But as you find out, a bit funky on mobile platforms. And now you've got different code for different parsers and lots and lots of confusion. What you need is fewer options not more. Concentrate on some basics. You are learning after all. I think you've taken a wrong turn after some well intended but, for your needs, inappropriate advice. – David Heffernan Feb 13 '15 at 12:58

1 Answers1

2

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490