FireMonkey Android problem with TIdHTTPServer

Viewed 148

I have an FireMonkey Android app with a TTabControl, TWebBrowser, and TIdHTTPServer.

I try to redirect HTTP clients to a new URL in the TIdHTTPServer.OnCommandGet event using the following code:

TabControl1.ActiveTab := TabItem2;
AResponseInfo.ResponseNo := 302;
AResponseInfo.Location := ARequestInfo.Params.Values['url'];

But I get an error:

Checksynchronize called from thread $c6f02970 which is NOT the main thread.

How can I change the tab after the request comes to TIdHTTPServer component?

1 Answers

The OnCommandGet event is executed in the context of a worker thread. You are only allowed to access the user interface from the main UI thread. Move access to UI controls embedded into a call to TThread.Synchronize or TThread.Queue.

TThread.Synchronize(nil,
  procedure
  begin
    Tabcontrol1.ActiveTab:=tabitem2;
  end);
AResponseInfo.ResponseNo := 302;
AResponseInfo.Location := ARequestInfo.Params.Values['url'];
Related