🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.intrabuilder.forms
Article #40

Re: Where can I define a form variable?

#40
From: Marcelo M. Marques
Date: Wed, 23 Sep 1998 00:00
316 lines
8649 bytes
This is a multi-part message in MIME format.
--------------8F6D143BB017D8555B3BAB90
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi Rem,

I'm not sure of my previous guess (quoted below) because as I don't need this
addressing in my application, I never tried or tested it. I am sending attached
one of the FAQ's file I got in Borland that tells something about other risks.
Also I found these quotations in the book "Teach Yourself Intrabuilder in 21
Days" from "Sams Net" and "Borland Press".

(at page 653):
"So, where can you store an object reference that is visible to every object and
function in your IntraBuilder application ? You store it in a custom property of
the global _sys object."

(and at page 656):
"The _sys object is global only to a single IntraBuilder Agent. When you are
running applications with more than one IntraBuilder Agent, you cannot share
information through the _sys object."

Regards,
MMM
-- 

Remigiusz Sokolowski wrote:
> 
> > Hi, Anthony and Rem,
> >
> > If I'm not wrong, putting a variable as a property of the _sys it will make that
> > variable visible to all sessions sharing the same Agent where your form was
> > opened, because the _sys reference is the Agent itself. Then, other forms of
> > other users' sessions in that Agent will change the value of that variable. Best
> > to create a property in the form to keep the value.
> >
> > Regards,
> > MMM
> Hi!:-)
> I'm not so sure if it is so, that all sessions see this property - I talk
> about that some time ago on this list and I thought that _sys properties
> are visible only for one user - I may be wrong.
>         Rem
> 
> -------------------------------------------
> Remigiusz Sokolowski
> e-mail: rems@gdansk.sprint.pl
> -------------------------------------------
--------------8F6D143BB017D8555B3BAB90
Content-Type: text/html; charset=us-ascii; name="faq069.htm"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="faq069.htm"
Content-Base: "file:///D|/Borland/IntraBuilder/Faq/fa
	q069.htm"

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN" "html.dtd">

<HTML>

<HEAD>

<TITLE>FAQ069 - Sharing Database Objects Among Forms</TITLE>

</HEAD>





<!--End of Header -->

<BODY BGCOLOR=#FFFFFF LINK=#126566> 

<H3><center><B>Sharing Database Objects Among Forms</B></CENTER>

</H3>

<P>

<FONT SIZE=2><B><I>FAQ Number: 069<BR>

IntraBuilder Version: 1.0 and up<P></FONT></I></B>

<HR SIZE=3 NOSHADE>





<P><B>

QUESTION:</B>

<BR>How can you share database objects among forms?

<BR><P><B>ANSWER:<BR></B>

There may be times in which you find yourself creating more then one form for

your IntraBuilder application, each using tables from the same database.  

Normally this is fine, however performance issues may arise when an application has

several forms.  Each time a subsequent form is called, there are time and resources

taken up to establish a connection to the database, as well as to create the 

database object in memory.  There are a couple of options one could take in

which to have forms share the same database resources.  

<P>

The first option is to have a multiple page form, rather than having several forms.

Each page of the form would share the data objects and have the necessary components

for a specific operation.  The benefit of this is that development is very easy.

In the Form Designer, simply add the data access objects once and then add 

visual components on the appropriate pages.  An object such as a button could

change the forms page rather then run a separate form:

<PRE>

     function button1_onServerClick()

     {

         form.pageno = 2;

     }

</PRE>

The potential problem with this method is that all aspects of your project

(i.e. all components, methods, arrays, etc.) would need to be instantiated up 

front, taking up valuable resources.  In addition, the form would take a 

while to initially render.  Use multiple pages with a great deal of consideration

for resources.

<P>

The second option is to stay with multiple forms and create a single database object.

The database reference can then be 'hung' off _sys.  _sys is the IntraBuilder system

object and can be seen from any code on any form or report.  For more information 

on _sys see the IntraBuilder help.

<P>

WARNING:  You must be careful when using a public reference such as this.  It is

possible for one form to overwrite or destroy a value or object reference which

has been created off _sys.  The following technique prevents problems among forms

to some degree, but there is no guarantee that you or someone else won't write code

which effects this reference.

<P>

Once you have created your forms independently, and they all run, open them in 

the Script Editor.  Scroll down to the database definition.  Cut the entire

'with' statement for the database and paste it into the header (the very

top of the code).  Modify it as follows:<P>

<PRE>

     ** Before Modification **

     with (this.database1 = new Database()){

          left = 2;

          top = 1;

          databaseName = "LOCAL_IB";

          active = true;

     }

     // {End Header} Do not remove this comment//

     // Generated on 11/02/96

     //



     ** After Modification **

     try {

          x = _sys.db.count(); 		// test to see if associative array exists

     }

     catch (Exception e) {			// if the array doesn't exist create it

          _sys.db = new AssocArray()

          try { 	// test to see if LOCAL_IB has been defined

	       y = _sys.db["LOCAL_IB"].databaseName

          }



          catch (Exception L) {		// if LOCAL_IB hasn't been defined

               _sys.db["LOCAL_IB"] = new Database();

               // LOCAL_IB corresponds to a BDE alias

     	       _sys.db["LOCAL_IB"].databaseName = "LOCAL_IB";  

     	       _sys.db["LOCAL_IB"].active = true;

          }

     }



     // {End Header} Do not remove this comment//

     // Generated on 11/18/96

     //

     </PRE>

Next modify your query objects which reference this database.  Change the database

property so that it points to the database reference in the array.  For example:

<PRE>

     with ( this.employee1 = new Query() ) {

          database = _sys.db["LOCAL_IB"];	//  <<------ Modification is made here

          sql      = "SELECT * FROM EMPLOYEE";

          active   = true;

     }

</PRE> 

Do this for each form in your application in which you want to share the database

(in this example LOCAL_IB refers to a BDE alias to an InterBase database).  By

doing this, your application will save time from having to reconnect to the database 

server.  If a second form is called, a test is made to see if the array already 

exists and if the database has already been established.  

<P>

The benefit of this method is performance.  It can take several seconds for the 

IntraBuilder server to establish a connection with a remote SQL server.

<P>

The drawbacks are:

<OL>

<LI>Risk of the _sys.db array being inadvertently wiped out by other forms.

<LI>The username and password for that database (and all the privileges with 

that user) are used by anyone who accesses the forms.  

<LI>These forms cannot be modified in the Forms Designer until the form is 

actually run (the Forms Designer doesn't run the header).

</OL>

<BR><BR>

<A HREF="/devsupport/intrabuilder/w_faq.html">View list of FAQs</A><P>

<I><FONT SIZE=2>Last modified: March 31, 1997</I></FONT>





</BODY>

</HTML>


--------------8F6D143BB017D8555B3BAB90--
Technical Details
Message-ID: <36090B31.3A85E2C7@unisys.com.br>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <01bde561$18fdb330$5a2c40c1@fiws090> <Pine.GS4.4.02A.9809221004040.25822-100000@netra.gdansk.sprint.pl> <3607F629.D4269BE4@unisys.com.br> <Pine.GS4.4.02A.9809230850550.15306-100000@netra.gdansk.sprint.pl>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 14644c,427e54f4edebf5e4
X-Google-Attributes: gid14644c,public
From: "Marcelo M. Marques" <mmmrqs@unisys.com.br>
Subject: Re: Where can I define a form variable?
Date: 1998/09/23
Message-ID: <36090B31.3A85E2C7@unisys.com.br>
X-Deja-AN: 394035375
References: <01bde561$18fdb330$5a2c40c1@fiws090> <Pine.GS4.4.02A.9809221004040.25822-100000@netra.gdansk.sprint.pl> <3607F629.D4269BE4@unisys.com.br> <Pine.GS4.4.02A.9809230850550.15306-100000@netra.gdansk.sprint.pl>
To: Remigiusz Sokolowski <rems@gdansk.sprint.pl>
Content-Type: multipart/mixed; boundary="------------8F6D143BB017D8555B3BAB90"
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.intrabuilder.forms