HTTPRoute.pas and TRouteObject

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

HTTPRoute.pas and TRouteObject

Kevin Jesshope
Hi,

Working on a standalone web project using the new routing. I have a
class descended  from TRouteObject.

My problem is that the constructor cannot be marked override so it is
not called when the class is created by HTTPRouter.

Adding an empty virtual TRouteObject.create resolves this.

Is this a bad idea? Am I missing something?

Regards

Kevin
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: HTTPRoute.pas and TRouteObject

Michael Van Canneyt


On Sat, 10 Feb 2018, Kevin Jesshope wrote:

> Hi,
>
> Working on a standalone web project using the new routing. I have a
> class descended  from TRouteObject.
>
> My problem is that the constructor cannot be marked override so it is
> not called when the class is created by HTTPRouter.
>
> Adding an empty virtual TRouteObject.create resolves this.

I have added a virtual constructor in rev. 38180

>
> Is this a bad idea? Am I missing something?

It's not a bad idea, but IMHO unnecessary. The object is created,
HandlRequest is called and then destroyed. If you need the constructor to
create extra things,  you can just as well do this in HandleRequest.

To separate the 'initialization' from the actual handling of the request
you can do

Procedure TMyRouteObject.HandleRequest(aRequest : TRequest; aResponse : TResponse);

begin
   InitObject;
   // Do whatever;
end;

and in the destructor you then clean up. If you want to create a hierarchy
of objects, yoy make InitObject virtual, override it in descendents and
you're all set;

But I've added a virtual constructor to TRouteObject, save you some hassle ;)

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: HTTPRoute.pas and TRouteObject

Kevin Jesshope
Thanks Michael,

I did consider putting everything in the HandleRequest  but I prefer
the virtual constructor.
Regards

Kevin Jesshope - In Touch Computer Support
Supporting Aberfoyle Hub R-7 and Happy Valley Primary Schools


On Sat, Feb 10, 2018 at 6:06 PM, Michael Van Canneyt
<[hidden email]> wrote:

>
>
> On Sat, 10 Feb 2018, Kevin Jesshope wrote:
>
>> Hi,
>>
>> Working on a standalone web project using the new routing. I have a
>> class descended  from TRouteObject.
>>
>> My problem is that the constructor cannot be marked override so it is
>> not called when the class is created by HTTPRouter.
>>
>> Adding an empty virtual TRouteObject.create resolves this.
>
>
> I have added a virtual constructor in rev. 38180
>
>>
>> Is this a bad idea? Am I missing something?
>
>
> It's not a bad idea, but IMHO unnecessary. The object is created,
> HandlRequest is called and then destroyed. If you need the constructor to
> create extra things,  you can just as well do this in HandleRequest.
>
> To separate the 'initialization' from the actual handling of the request
> you can do
>
> Procedure TMyRouteObject.HandleRequest(aRequest : TRequest; aResponse :
> TResponse);
>
> begin
>   InitObject;
>   // Do whatever;
> end;
>
> and in the destructor you then clean up. If you want to create a hierarchy
> of objects, yoy make InitObject virtual, override it in descendents and
> you're all set;
>
> But I've added a virtual constructor to TRouteObject, save you some hassle
> ;)
>
> Michael.
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: HTTPRoute.pas and TRouteObject

Marcos Douglas B. Santos
On Sun, Feb 11, 2018 at 4:24 AM, Kevin Jesshope <[hidden email]> wrote:
>
> Thanks Michael,
>
> I did consider putting everything in the HandleRequest  but I prefer
> the virtual constructor.

I would like to suggest you do not use inherited classes from
TRouteObject as its business classes.
Inside HandleRequest you can instantiate any business classes that you
want and your code won't need fpWeb to test it. Make them separated.

Best regards,
Marcos Douglas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal