Recent

Author Topic: [solved] About Embedding a webserver tutorial  (Read 767 times)

CapelliC

  • Jr. Member
  • **
  • Posts: 54
[solved] About Embedding a webserver tutorial
« on: July 29, 2020, 06:57:44 pm »
Was trying to apply this tutorial https://www.freepascal.org/~michael/articles/webserver1/webserver1.pdf to a simple application form.
Seems the TThread Synchronize signature method doesn't match, indeed a first parameter, of type TThread, is required, from the GUI handler

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.DoHandleRequest(Sender: TObject;
  2.   var ARequest: TFPHTTPConnectionRequest;
  3.   var AResponse: TFPHTTPConnectionResponse);
  4. begin
  5.   FURL:=Arequest.URL;
  6.   FServer.Synchronize(@ShowURL); // error here
  7.   FHandler.HandleRequest(ARequest,AResponse); // I will replace FHandler with mine
  8. end;
  9.  

What is the GUI TThread handler ?
« Last Edit: July 30, 2020, 11:26:51 am by CapelliC »

PascalDragon

  • Hero Member
  • *****
  • Posts: 2259
  • Compiler Developer
Re: About Embedding a webserver tutorial
« Reply #1 on: July 30, 2020, 09:51:34 am »
You need to use Nil here. It's about the current thread, not the target thread, and the event handler will be called in the context of the server thread.

Did you put the server thread class into a separate unit to the form or in the same unit? If the former then this might explain why it worked for the author MvC, because the visibility rules allow you to access protected members of a parent class declared in a different unit (in this case the protected Synchronize with one parameter declared in Classes.TThread).

CapelliC

  • Jr. Member
  • **
  • Posts: 54
Re: About Embedding a webserver tutorial
« Reply #2 on: July 30, 2020, 11:26:32 am »
Thanks, it worked.

Guess you meant 'members of a parent class declared in the same unit' instead of
members of a parent class declared in a different unit
.

Now trying to gracefully stop the HTTP server. Terminate doesn't have effect...

PascalDragon

  • Hero Member
  • *****
  • Posts: 2259
  • Compiler Developer
Re: About Embedding a webserver tutorial
« Reply #3 on: July 30, 2020, 11:57:01 am »
Guess you meant 'members of a parent class declared in the same unit' instead of
members of a parent class declared in a different unit

No, I meant it as I wrote it. If you have a class A in unit X that inherits from a class B in unit Y then any code in unit X (even outside class A) can access protected members of class B.

CapelliC

  • Jr. Member
  • **
  • Posts: 54
Re: [solved] About Embedding a webserver tutorial
« Reply #4 on: July 30, 2020, 12:02:33 pm »
Ok, thanks for the explanation.
I'm such a noob at FPC... :(

PascalDragon

  • Hero Member
  • *****
  • Posts: 2259
  • Compiler Developer
Re: [solved] About Embedding a webserver tutorial
« Reply #5 on: July 30, 2020, 01:18:53 pm »
Don't feel bad about this. I had to think a bit about this as well, as I usually don't encounter this. ;)

 

TinyPortal © 2005-2018