View Complete Thread | FoxWeb Forum Home
Date:    Msg ID:   
From:    Thread:   
Thanks for your reply. I see what you mean by using FW_enter.prg  and then testing to see if the COM object or procedure has been previously established. I think procedures would provide a more efficient method, and they are easier to debug.


Sent by FoxWeb Support on 08/27/2006 06:49:56 PM:
It's possible to keep COM objects and VFP classes in memory by assigning them to PUBLIC variables in fw_enter.prg.  To prevent these variables from being instantiated on every request, you can use code like the following:


IF VARTYPE(M.MyObject) = "U"

    PUBLIC M.MyObject

    M.MyObject= CREATEOBJECT('ApplicationName.Class')


The object will be created once for each channel.  When a channel is restarted, then the object will be re-created at the beginning of the first request served by that channel.
Although I'm not sure whether you will get a performance boost, you can use a similar technique for SET PROCEDURE commands:





FoxWeb Support Team email

Sent by John Sullivan on 08/26/2006 01:30:06 PM:

My question relates to procedures and/or COM objects that are called from FWX pages. Where is the best location to establish programs or COM objects?

For example, I have a FWX page that I need to query a database than contains a record for every zip code in the US. To keep things simple I want to display information about each zip code on a State + County basis. This will allow us to keep the page size to a reasonable size for the user.

We have one combo box #1 to select the state. Obviously we use a SELECT statement to obtain just the individual states on a UNIQUE basis. We have another combo box #2 that contains the counties for the specific state displayed in the first combo box #1. When the user selects a different state we need to re-query the master database twice to setup the combo boxes. We also need to build the HTML for each combo box display.

As you can see, the above requires lots of code. I place to locate the code in a COM object and then do a Px = CreateObject("myserver.myclass") at the start of the script to establish the COM object.

This raises several questions, which are:

  1. I don't want the overhead of establishing the COM object with each hit to the page and then releasing it after it is done. Where can I establish the COM object just once and then use it freely in this, and other scripts?
  2. What happens to the COM object is channels are restarted. Do I need to reset the COM object?
  3. Any suggestions on where it is best to locate processing code, where to use SET PROCEDUE TO {library} and so on in FWX scripts or server setup code?

Thanks for your insight to a "best programming practices" relative to FoxWeb.

John Sullivan