I just realized that my exceptions are not displayed to the user in my threads!
First I used this in my thread to throw an exception that does not work:
except on E:Exception do begin raise Exception.Create('Error: ' + E.Message); end;
The IDE shows me exceptions, but my application does not work!
I reviewed the solution, here is what I found:
Delphi Thread Exclusion Mechanism
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22039681.html
And not one of them worked for me.
Here is my theme unit:
unit uCheckForUpdateThread; interface uses Windows, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, GlobalFuncs, Classes, HtmlExtractor, SysUtils, Forms; type TUpdaterThread = class(TThread) private FileGrabber : THtmlExtractor; HTTP : TIdHttp; AppMajor, AppMinor, AppRelease : Integer; UpdateText : string; VersionStr : string; ExceptionText : string; FException: Exception; procedure DoHandleException; procedure SyncUpdateLbl; procedure SyncFinalize; public constructor Create; protected procedure HandleException; virtual; procedure Execute; override; end; implementation uses uMain; { TUpdaterThread } constructor TUpdaterThread.Create; begin inherited Create(False); end; procedure TUpdaterThread.Execute; begin inherited; FreeOnTerminate := True; if Terminated then Exit; FileGrabber := THtmlExtractor.Create; HTTP := TIdHTTP.Create(nil); try try FileGrabber.Grab('http://jeffijoe.com/xSky/Updates/CheckForUpdates.php'); except on E: Exception do begin UpdateText := 'Error while updating xSky!'; ExceptionText := 'Error: Cannot find remote file! Please restart xSky and try again! Also, make sure you are connected to the Internet, and that your Firewall is not blocking xSky!'; HandleException; end; end; try AppMajor := StrToInt(FileGrabber.ExtractValue('AppMajor[', ']')); AppMinor := StrToInt(FileGrabber.ExtractValue('AppMinor[', ']')); AppRelease := StrToInt(FileGrabber.ExtractValue('AppRelease[[', ']')); except on E:Exception do begin HandleException; end; end; if (APP_VER_MAJOR < AppMajor) or (APP_VER_MINOR < AppMinor) or (APP_VER_RELEASE < AppRelease) then begin VersionStr := Format('%d.%d.%d', [AppMajor, AppMinor, AppRelease]); UpdateText := 'Downloading Version ' + VersionStr; Synchronize(SyncUpdateLbl); end; finally FileGrabber.Free; HTTP.Free; end; Synchronize(SyncFinalize); end; procedure TUpdaterThread.SyncFinalize; begin DoTransition(frmMain.TransSearcher3, frmMain.gbLogin, True, 500); end; procedure TUpdaterThread.SyncUpdateLbl; begin frmMain.lblCheckingForUpdates.Caption := UpdateText; end; procedure TUpdaterThread.HandleException; begin FException := Exception(ExceptObject); try Synchronize(DoHandleException); finally FException := nil; end; end; procedure TUpdaterThread.DoHandleException; begin Application.ShowException(FException); end; end.
If you need more information, just let me know.
Again: the IDE catches all exceptions, but my program does not show them.
EDIT: it was a Cosmin solution that worked in the end - and the reason it was not in the beginning was because I did not add the ErrMsg variable, instead I just placed any variable in Synchronize that would not work, but I I do not know why. I realized this when I had no other ideas, and I just messed up the solutions.
As always, the joke is about me. = P