Jump to content

Recommended Posts

OK, I was trying to ask how to rewrite a Application that I create using thread to be more responsive, then I found this video:

OmniThread Library - Primoz Gabrijelcic Thursday, September 3, 2015

What I need starts at  Async/Await demo (t=300)

So I'll leave the link, I will see it, read and practice to see if I can re write my application.

Regards

 

 

Share this post


Link to post
10 minutes ago, Primož Gabrijelčič said:

@KodeZwerg Fixed, thank you!

Confirm. Thankyou for that great resource!

Edited by KodeZwerg

Share this post


Link to post

Strange, I recompile two projects (Berlin), now, running on the target computer, the previous versions works but the new version shows this message:

(of course I just jump on the video and don't read the docs :shame, following @KodeZwerg advice now)

Quote

Exception: 10/27/2018 10:22:42.389
----------------------------------------------------------------------------
Microsoft MSXML is not installed

 

Share this post


Link to post

I don't find any information about OTL related with this msxml issue.

Looks like is not related, maybe is something wrong with my project configuration.

I'll check the project/IDE, recompile the original code and see if this error occurs. (fingers crossed) :classic_unsure:

Share this post


Link to post

@Primož Gabrijelčič, yes the exception pops up. I remotely connect to my office to check it, and now I see that I'm using and OTL old version, updating now.

The exception occurs, following @Schokohase advice and was right.

Looks like access that web services needs your advice to works. So I need  to add "ActiveX" on the uses clause:

uses ...
  , ActiveX
  , OTLparallel;
  
// add the 
procedure TForm1.doConnectionToService
begin
   try
     CoInitialize(nil);
     //...
     wsServicio := Servicio.GetServicioSoap(cbUseWSDL.Checked);
     //...
   except
     on E : Exception do
     begin
     	//...
     end;
   end;
   CoUninitialize;
end;

// on my clic event
procedure TForm1.bbConectarClick(Sender: TObject);
begin
  bbConectar.Caption:= 'Comprobando Acceso...';
  bbConectar.Enabled:= False;
  
  // The old annoying unresponsive way:
  // doConectar;
  // bbConectar.Caption:= '&1) Comprobar Acceso';
  // bbConectar.Enabled:= True;
  
  // The new code without unresponsive GUI! Thank you Primoz G.
  Async(doConectar)
    .Await(
    procedure
    begin
      bbConectar.Caption:= '&1) Comprobar Acceso';
      bbConectar.Enabled:= True;
    end);
end;

Maybe there need to be a new entry in the OTL FAQ because I don't find any reference (I wasn't searching thoroughly).

 

Thank you for the help!

 

Regards

 

image.png

Share this post


Link to post

But this is not an OTL issue.

 

The SOAP client uses MSXML and MSXML needs CoInitialize.

 

Delphi already do call it for you in GUI applications for the UI thread. But in a console application you have to do that by yourself, as you have to call that on any other thread.

 

You will have the same problems when working with TThread or TPL or OTL or ... anything else which will use a thread different from the main thread.

  • Thanks 1

Share this post


Link to post
5 minutes ago, Schokohase said:

But this is not an OTL issue.

...

You will have the same problems when working with TThread or TPL or OTL or ... anything else which will use a thread different from the main thread.

Hence the nature of this post, for the new users of this great library.

But it's official, I need to read more documentation of OTL, learn and be aware of changes that need care, Delphi really do a great job lifting the weight for us.

 

I manage to fix one application; and I got a some more that can beneficed using OTL.

 

Some other app trows me an unexpected AV error, it just consume another web services, open some xml file, inspect that some elements are present then upload to that service.

At the end, closing the app got this: Delphi and threads: “System Error. Code: 1400. Invalid window handle (need to read tomorrow and fix it)

Regards!

Share this post


Link to post
16 hours ago, Mr. E said:

Maybe there need to be a new entry in the OTL FAQ because I don't find any reference (I wasn't searching thoroughly).

This is mentioned in the book: http://www.omnithreadlibrary.com/book/chap10.html#howto-com 

 

P.S. Make sure that you don't call any VCL code from your background threads!

Edited by Primož Gabrijelčič
  • Thanks 1

Share this post


Link to post
9 hours ago, Primož Gabrijelčič said:

This is mentioned in the book: http://www.omnithreadlibrary.com/book/chap10.html#howto-com 

 

P.S. Make sure that you don't call any VCL code from you background threads!

Thank you @Primož Gabrijelčič, now I know what to read & learn "7.12 OmniThreadLibrary and COM/OLE" :classic_love:

 

Edit:

Seeing your recommendation about VCL; if I need to update a TListView with the output of each call of the web service, then I'll need to divide my code so I can update that VCL controls. 💭

 

Edit #2:

@Primož Gabrijelčič Is correct this approach?

Asyn(do_something_with_the_webservices)
.Await(
    procedure
    begin
      // Can I update ListView controls here?
      // ... more code inside
    end);

 

Edit #3 . (To myself) First read the docs, then ask later! [ self.slap :classic_blink:]

..

Edited by Mr. E
..

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×