elGringo Posted December 26, 2017 Share Posted December 26, 2017 Hi, in vcl doing like this... TTestThread = class(TThread) private fEx : Exception; procedure QueryError; protected procedure Execute; override; end; procedure TTestThread .Execute; begin inherited; try // my code except fEx := ExceptObject as Exception; Synchronize( QueryError ); end; end; procedure TTestThread .QueryError; begin Application.OnException( Self, fEx ); end; How to do the same in UniGUI? Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 tried this but didn't help procedure THTTPThread.Execute; var r,a,b: double; begin { Place thread code here } //http request try if Assigned(FHTTPRequestFunction) then FHTTPRequestFunction(); b:=0; a:=1; r := a / 0; // raises exception here but dont switch to exception block... // raise Exception.Create('Error Message'); except on E: Exception do begin Synchronize( procedure begin UniApplication.UniSession.ShowAlert('Произошла ошибка ' + E.Message + #13#10 + 'Попробуйте ещё раз'); end) end; end; end; Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 is anybody alive? Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 also tried this but also didn't help... Synchronize( procedure begin if Assigned(FSomeObject) then (FSomeObject as TTestFrame).showException(E.Message); // UniApplication.UniSession.ShowAlert('Произошла ошибка ' + E.Message + #13#10 + 'Попробуйте ещё раз'); end) Quote Link to comment Share on other sites More sharing options...
delagoutte Posted December 26, 2017 Share Posted December 26, 2017 are you sure that the problem is the exception catching ? maybe your problem is only for displaying the error to the user. Could you try to save your exception in a log file and don't try to display it Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 i'm sending request to http and 1/5 response with error - i want to inform user to repeat this request, so yes, i need it to display Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 tried through procedure of object, also failed... TExceptionNotify = procedure(AMsg: string) of object; procedure THTTPThread.Execute; var r, a, b: double; begin { Place thread code here } //http request try if Assigned(HTTPRequestFunction) then HTTPRequestFunction(); b := 0; a := 1; r := a / 0; // raise Exception.Create('Error Message'); except on E: Exception do begin Synchronize( procedure begin if Assigned(FExceptionNotify) then FExceptionNotify('123'); end) end; end; end; starting to think that unigui deny such messages from threads... to main thread.... Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 now it falls to exception block, but ! when calling FExceptionNotify it raises new exception... with AV and i call with if Assigned(FExceptionNotify) - gently, so it seems to me problem somewhere in unigui Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 finally TNotifyEvent falls to AV ... if Assigned(FNotifyEvent) then FNotifyEvent(nil); ... Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 kind of mystery for me... Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 so guys, if you have ideas, please share, wanna try working one if somebody knows what's up... all i want to send request in thread, because requests take 3-10 seconds and sometimes the fall to socket error or bad request - so i want to inform my user what's up, i don't want my user to wait this time Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 for the moment i cannot even inform that thread is over (( Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 maybe it is better to use callbacks here rather than threads? Quote Link to comment Share on other sites More sharing options...
delagoutte Posted December 26, 2017 Share Posted December 26, 2017 i don't say to not use display the problem to user. I think that your problem is not to catch the exception. You could verify this with using a log file and not display for test. i think you would be have lines with exception in log file with this method. i think that the problem is to synchronize server side with client side for display the error message. maybe it is better to use callbacks here rather than threads? Maybe ? maybe threadTimer exemple could help you ? Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 limitations of framework... Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 threadTimer but how? Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 so you see sessions don't give message from one thread to another ( so i put antifreeze component and handled on beginWork event and onEndWork with moving progressBar, but! it begin working in GUI right after idHTTP processed the request i fill myself on the moon, seems to be Delphi but not Delphi, pseudo Delphi in some places ))) Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 tried so send httpRequest from thread - catched AV... seems to be its forbidden Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 seems to me for background job its better use neighbour server... Quote Link to comment Share on other sites More sharing options...
elGringo Posted December 26, 2017 Author Share Posted December 26, 2017 have an idea to use indy http server and use idea of webhooks with back links (when job is done 2-d server will send ajax request to unigui if, of course unigui will allow to get request from other servers...) Quote Link to comment Share on other sites More sharing options...
elGringo Posted January 8, 2018 Author Share Posted January 8, 2018 solved in, when setup another vcl app with idHttpServer and sent requests there... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.