Forum > Android

Can I use TThread in android app in the same way like for windows app?

(1/2) > >>

Atak_Snajpera:
I have added cthreads to lpr file then I try creating and running thread the same how I do on windows.

Simple example:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TWorkerThread = class(TThread)  private    { Private declarations }    x:integer;    procedure UpdateValue;  protected    procedure Execute; override;  end;    

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.ButtonClick(Sender: TObject);begin       WorkerThread:=TWorkerThread.Create(true);     WorkerThread.FreeOnTerminate:=false;     WorkerThread.Priority:=tpNormal;     WorkerThread.Start; end;        

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TWorkerThread.Execute;begin   x:=0;       repeat         Inc(x);         Synchronize(UpdateValue);         sleep(1000);   until Terminated=true; end;  

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TWorkerThread.UpdateValue;begin   form1.jTextView.text:=IntToStr(x);  end;
When I press button in android emulator nothing happens!

engkin:
TThread works on Android.

Synchronize needs CheckSynchronize to be called inside the main loop of the app. This is by default on Windows for GUI applications. Not on terminal or Android apps. You can add it there.

Test TThread without Synchronize.

Atak_Snajpera:
Where should I put CheckSynchronize exactly?

MarkMLl:
Seconded. @engkin, could we have a concise example please?

MarkMLl

engkin:
I'll provide an example as soon as get a chance.

Navigation

[0] Message Index

[#] Next page

Go to full version