Jump to content
Sign in to follow this  
DidierXT

TypeError - Converting circular structure to JSON 

Recommended Posts

Hi,

I don't understand then reason with of this error.
Any idea please?

Thanks

 

////// GLOBAL //////

type 
 TFichier = class(JObject)
    nom  : string;
    data : string;
  end;

//************* FORM *************

// file informations
var fichier := new TFichier;
fichier.nom := edPhoto1.Text;
fichier.data := imgPhoto1.ToDataUrl;

// POST message to threaded webworker
var up := TUploadThread.Create();
BrowserAPI.Window.postMessage(fichier, '*');


//************* WEBWORKERTHREAD *************

procedure TUploadThread.ReceiveMessage(Data: Variant);
var
  bd : TBinaryData;
begin
  var fic := TFichier(Data);
  bd := TBinaryData.Create();
  bd.AppendBytes(TDataType.StringToBytes(fic.data));

  FROServeur.GetServerTime(
    procedure (aResult: DateTime) begin
      writeln('Connexion serveur (thread): ' + aResult.toDateString);
      FROServeur.AddPhoto(
        '',
        fic.nom, 
        bd,            // <<<<<<<<==== ???
        procedure (aResult: AnsiString)
        begin
          Writeln('Fichier: ' + fic.nom + ' : sent !');
        end,
        procedure (aMessage: TROMessage; aError: JError)
        begin
          Writeln('Fichier: ' + fic.nom + ' : ' + aError.name + ' - ' + aError.message);
		  //************* TypeError - Converting circular structure to JSON *************
        end
        );
    end,
    procedure (aMessage: TROMessage; aError: JError) begin
      writeln('Connexion serveur (thread) : IMPOSSIBLE');
    end);

 

Share this post


Link to post
Share on other sites

not sure if this answers your question, but did notice you're sending a postmessage to the window object. That is usually done to enable cross or intra-window communication. If you want to communicate with a specific webworker, send it to that webworker instead. 

monOuvrier.postMessage([fichier]);

Share this post


Link to post
Share on other sites
Quote

If you want to communicate with a specific webworker, send it to that webworker instead. 

Note that I use a TWebWorkerThread.
I tried, with no success. The PostMessage implementation is void in SmartCL.Webworker.pas
.

Share this post


Link to post
Share on other sites

Hum, seems I misunderstood the whole webworker process...
I have to implement the "webworker.js"

But I'm unable to have the OnMessage triggered in the démo project.

Any idea ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×