NetTalk Central

Author Topic: Adding properties to NetWebServerWorker object  (Read 2019 times)

CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Adding properties to NetWebServerWorker object
« on: May 07, 2010, 12:59:52 PM »
Using NT4 for now.

I use p_web.GSV extensively, usually for dynamic values but also for some values that are static for the session.  I use some of these static values in concatenated filters, some quite complex. Dealing with the extra single quotes adds a lot of additional complexity.  I would like to simply add these values as properties of the NetWebServerWorker, so the filters would be:

 .....&p_web.StaticValue1&......

  instead of

 ....&p_web.GSV('StaticValue1')&......

It would also help for concatenated prompts, comments, and tooltips, but filters are the big issue.
 
Is there a way to add properties to the NetWebServerWorker object without touching either the shipped NetTalk classes or templates?    If not in NT4, how about NT5?  Still no, would you consider an embed point in the templates to do so in the future, Bruce?

Thanks.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11181
    • View Profile
Re: Adding properties to NetWebServerWorker object
« Reply #1 on: May 07, 2010, 09:26:54 PM »
Hi Casey,

You can add new properties to the class at the moment, but unfortunately it's not that easy to _use_ them. Let me explain.

Firstly, on the NetTalk extension, on the WebHandler procedure, on the Classes tab you can declare extra properties and methods for the class. So that takes care of that bit, and extra embed points are not really needed.

However, the WebHandler object is then passed off to all the other procedures creating the familiar p_web object.
In other words, p_web exists in all those browses and forms, because it is passed in as a parameter. The parameter declaration looks like this;

(NetWebServerWorker p_web)

The important thing there is that the NetWebServerWorker class is explicitly mentioned, so that the receiving function (the browse, form, whatever) knows what it is. Since this is the _parent_ class (ie the shipping nettalk class) not the _derived_ object you've created in WebHandler, the browse or form doesn't know about your addions and hence can't use them.

But wait there's more.

Another point that comes into play here is that the WebHandler object is very short lived. When a request comes into the server a new handler object is created (on a new thread). It exists for a fraction of a second, doing whatever it has to do, then the thread ends, and the object is discarded. So even if you have an extra property, it only lasts for a very short time. It's not tied to a session or a user.

There is an approach you can use though if you really really want to add properties, and you understand the issues involved. You can create a derived class, in the libsrc folder, which derives from the NetWebServerWorker class, and adds a couple properties to it. It's not hard to do, but is a little finicky if you haven't used classes before. If done right the new class will appear in the drop-down on the nettalk extension (in the web handler) and you can use that class. You will then however need to change the prototype in all your web procedures to reflect the new class.

I think you'll find the threading issue is the fundamental break though. So before you go to all the trouble of creating a derived class, simply add a property to the existing class definition (in netweb.inc) and see if it actually does help you at all.

Cheers
Bruce

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Adding properties to NetWebServerWorker object
« Reply #2 on: May 08, 2010, 04:10:15 AM »
Hi Casey,

I found the same problem working with extra single quotes in SQL - it made my code really hard to read and debug. However using the ASCII equivalent <39> I found really helped and I use the same in Nettalk.

Cheers,

Kevin