xrealtv xrealtv
xrealtv xrealtv

Reputation: 67

FireMonkey Android problem with TIdHTTPServer

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?

Upvotes: 2

Views: 198

Answers (1)

NineBerry
NineBerry

Reputation: 28499

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'];

Upvotes: 3

Related Questions