[Solved] TMyThread.Create(True) causes error lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- teriyaki · 2022-01-21 16:07 the code below works on Windows Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TMyThread = class(TThread)  private   public   end; when I call Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i myThread := TMyThread.Create(True) on macOS it reports error as attached image. Your comment welcome ---------------------------------------------------------------------- korba812 · 2022-01-21 16:16 The TThread.Execute method is an abstract method. You have to implement this method in your class. Or add "cthreads" unit to "uses" section. ---------------------------------------------------------------------- teriyaki · 2022-01-22 01:30 I did Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i constructor TMyThread.Create(CreateSuspended: boolean);begin  inherited Create(CreateSuspended);  FreeOnTerminate := True;end; procedure TMyThread.Execute;begin end; it works well on Windows 10. ---------------------------------------------------------------------- trev · 2022-01-22 03:07 As korba812 told you, you need to add the "cthreads" unit to "uses" clause. For more detail see the Wiki article Units needed for a multi-threaded application. ---------------------------------------------------------------------- teriyaki · 2022-01-22 12:18 if I add the code below, Lazarus can build the project and create the execute app. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses{$ifdef DARWIN}   cthreads,{$endif}              but the app can not run, nothing happens if I remove the code above, it can launch the app correctly. ---------------------------------------------------------------------- trev · 2022-01-22 22:22 Quote from: teriyaki on January 22, 2022, 01:18:38 pmif I add the code below, Lazarus can build the project and create the execute app. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses{$ifdef DARWIN}   cthreads,{$endif}              In which file did you add the code? Quotebut the app can not run, nothing happens What does the Applications > Utilities > Console log show? What happens if you run the executable and not the application bundle? ---------------------------------------------------------------------- teriyaki · 2022-01-27 05:58 I created a empty project and made it work with cthread, but it still report error Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit mainformunit; {$mode objfpc}{$H+} interface uses{$ifdef DARWIN} cthreads,{$endif}     IdSSLOpenSSL, Classes, SysUtils, Forms,    Controls, Graphics, Dialogs, StdCtrls, IdHTTP, ZConnection; type  TMyThread = class(TThread)  private     procedure completedAction;  protected    procedure Execute; override;  public    threadHTTP: TIdHTTP;      constructor Create(CreateSuspended: boolean);   end; type   { TForm1 }   TForm1 = class(TForm)    Button2: TButton;  IdHTTP1: TIdHTTP;    ZConnection1: TZConnection;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var  myThread: TMyThread;begin   myThread := TMyThread.Create(True);  myThread.threadHTTP:=TIdHTTP.Create(nil);   myThread.Start; end; procedure TForm1.Button2Click(Sender: TObject);var  myThread: TMyThread;begin   myThread := TMyThread.Create(True);  myThread.threadHTTP:=TIdHTTP.Create(nil);   myThread.Start; end; constructor TMyThread.Create(CreateSuspended: boolean);begin  inherited Create(CreateSuspended);  FreeOnTerminate := True;end; procedure TMyThread.completedAction;// this method is executed by the mainthread and can therefore access all GUI elements.begin end; procedure TMyThread.Execute;var  n, i: integer;  responseContentString: string;  lHTTP: TIdHTTP;  tIdSSLIOHandlerSocket: TIdSSLIOHandlerSocketOpenSSL; begin   tIdSSLIOHandlerSocket := TIdSSLIOHandlerSocketOpenSSL.Create(nil);  tIdSSLIOHandlerSocket.PassThrough := True;  with tIdSSLIOHandlerSocket do  begin    SSLOptions.Method := sslvTLSv1_2;    SSLOptions.SSLVersions := [sslvTLSv1_2];    SSLOptions.VerifyMode := [];    SSLOptions.VerifyDepth := 2;  end;   responseContentString := threadHTTP.Get('https://echo.hoppscotch.io') ;//error happened here    Synchronize(@completedAction);  //Synchronize(@Showstatus); end; end. ---------------------------------------------------------------------- cdbc · 2022-01-27 06:29 Hi Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$ifdef DARWIN} cthreads,{$endif} needs to be the first in your project-file !!!! Regards Benny ---------------------------------------------------------------------- trev · 2022-01-27 11:04 Quote from: cdbc on January 27, 2022, 07:29:43 amneeds to be the first in your project-file !!!! As noted in the Wiki link I posted. @teriyaki: please read Wiki links when provided to you as they nearly always contain useful information ---------------------------------------------------------------------- teriyaki · 2022-01-27 13:53 my project Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; {$mode objfpc}{$H+} uses{$ifdef DARWIN}cthreads,{$endif}   Interfaces, // this includes the LCL widgetset  Forms, zcomponent, indylaz, mainformunit  { you can add units after this }; {$R *.res} begin  RequireDerivedFormResource:=True;  Application.Scaled:=True;  Application.Initialize;  Application.CreateForm(TForm1, Form1);  Application.Run;end.                    mainformunit.pas Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit mainformunit; {$mode objfpc}{$H+} interface uses      IdSSLOpenSSL, Classes, SysUtils, Forms,    Controls, Graphics, Dialogs, StdCtrls, IdHTTP, ZConnection; type  TMyThread = class(TThread)  private     procedure completedAction;  protected    procedure Execute; override;  public    threadHTTP: TIdHTTP;      constructor Create(CreateSuspended: boolean);   end; type   { TForm1 }   TForm1 = class(TForm)    Button2: TButton;    IdHTTP1: TIdHTTP;    ZConnection1: TZConnection;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var  myThread: TMyThread;begin   myThread := TMyThread.Create(True);  myThread.threadHTTP:=TIdHTTP.Create(nil);   myThread.Start; end; procedure TForm1.Button2Click(Sender: TObject);var  myThread: TMyThread;begin   myThread := TMyThread.Create(True);  myThread.threadHTTP:=TIdHTTP.Create(nil);   myThread.Start; end; constructor TMyThread.Create(CreateSuspended: boolean);begin  inherited Create(CreateSuspended);  FreeOnTerminate := True;end; procedure TMyThread.completedAction;// this method is executed by the mainthread and can therefore access all GUI elements.begin end; procedure TMyThread.Execute;var  n, i: integer;  responseContentString: string;  lHTTP: TIdHTTP;  tIdSSLIOHandlerSocket: TIdSSLIOHandlerSocketOpenSSL; begin   tIdSSLIOHandlerSocket := TIdSSLIOHandlerSocketOpenSSL.Create(nil);  tIdSSLIOHandlerSocket.PassThrough := True;  with tIdSSLIOHandlerSocket do  begin    SSLOptions.Method := sslvTLSv1_2;    SSLOptions.SSLVersions := [sslvTLSv1_2];    SSLOptions.VerifyMode := [];    SSLOptions.VerifyDepth := 2;  end;   responseContentString := threadHTTP.Get('https://echo.hoppscotch.io') ;    Synchronize(@completedAction);  //Synchronize(@Showstatus); end; end. still reports error as the attached images ---------------------------------------------------------------------- engkin · 2022-01-27 17:36 @teriyaki, Did you notice the error message in your first post Is different from the message in your last post? AND The thread method was empty in your first post. Meaning your problem mentioned in the first post is solved. Now you have a different problem. Probably should create a new post for it. Your current problem is related to OpenSSL and You need to mention details of your setup. ---------------------------------------------------------------------- teriyaki · 2022-01-27 23:57 in the first post, I hope to make thing simple so I did not show all codes. At that time, if I add Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses cthread the project could be compiled but could not run correctly. so I created another empty project and added the code blocks one by one to keep it as a simplest project.(the code show above) Finally it can be run now. but it still reports same error since then my macOS version is Monterey 12.1 ---------------------------------------------------------------------- zoltanleo · 2022-01-28 07:29 Hey teriyaki Try to run this project (ignore the "dirty" code )