Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Class - Design or bug?

Status
Not open for further replies.

AChiado

Programmer
Mar 1, 2002
49
IT
Hi all,

I have a problem with session class and I dont know if i'm wrong or it is a vfp bug.

When I add a session control to a container with .AddObject() the session control dont create a own datasession. Instead if I create it with CreateObject() it creates a own datasession.

I use vfp 7 sp1
I dont know if is the same with vfp8.

I create a little sample:

create a table with some field and name it "tabella"

Then create a program with this code:

***
ON SHUTDOWN quit
oFormTest=CREATEOBJECT("formtest")
READ events

DEFINE CLASS formtest as form

PROCEDURE init

* oTest1=createobject("test1")
* oTest2=createobject("test2")
This.Addobject("oTest1","test1")
This.Addobject("oTest2","test2")

RETURN
ENDDEFINE

DEFINE CLASS test1 as session

PROCEDURE init

USE tabella
IF USED("tabella")
MESSAGEBOX("USED(TABELLA)")
ELSE
MESSAGEBOX("NOT USED(TABELLA)")
ENDIF

RETURN
ENDDEFINE

DEFINE CLASS test2 as session

PROCEDURE init

IF USED("tabella")
MESSAGEBOX("USED(TABELLA)")
ELSE
MESSAGEBOX("NOT USED(TABELLA)")
ENDIF

RETURN
ENDDEFINE
***

Can someone check for it?

Thank you

Andrea C.P.
Italy [atom] Turin
 
Andrea,

The behaviour you described is what I would expect. A session object is designed to be used as a free-standing object which manages its own datasession. I can't think of a good reason to add it to a container, but if you did do so, it seems reasonable that the datasession would be governed by that of the container.

Although I'm not completely sure about this, I believe that this behaviour is by design.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Your findings are correct and by design.

If you use the addobject() method or add object clause
in a form class definition, the additional datasession
will take on the datasession of the containing form.

Darrell

i.e.

Code:
Local oForm1, oForm2
oForm1 = CREATEOBJECT("clsForm1")
oForm2 = CREATEOBJECT("clsForm2")
oForm1.SHOW()
oForm2.SHOW()

Read EVENTS

Define CLASS clsForm1 AS FORM
  DoCreate = .T.
  Top = 10
  Left = 10

  Caption = "Datasession added with add object"
  bStartup = .T.

  Add OBJECT session1 AS clsDataSession

  Add OBJECT lblDataSessionId AS LABEL WITH ;
    AUTOSIZE = .T.

  Procedure ACTIVATE
    If THIS.bStartup
      This.bStartup = .F.
      With THIS.lblDataSessionId
        .CAPTION = ;
          "Form datasession = " + ;
          TRANSFORM(THIS.DATASESSIONID) + ;
          ", Session1's datasession = " + ;
          TRANSFORM(THIS.session1.DATASESSIONID)

        .TOP = THIS.HEIGHT / 2 - .HEIGHT / 2
        .LEFT = THIS.WIDTH / 2 - .WIDTH / 2
      Endwith
    Endif
  Endproc

  Procedure DESTROY
    Clear EVENTS
  Endproc

Enddefine

Define CLASS clsForm2 AS FORM
  DoCreate = .T.
  Top = 10
  Left = 400

  Caption = "Datasession added with createobject()"
  bStartup = .T.

  session1 = NULL

  Add OBJECT lblDataSessionId AS LABEL WITH ;
    AUTOSIZE = .T.

  Procedure INIT
    This.session1 = CREATEOBJECT("clsDataSession")
  Endproc

  Procedure ACTIVATE
    If THIS.bStartup
      This.bStartup = .F.
      With THIS.lblDataSessionId
        .CAPTION = ;
          "Form datasession = " + ;
          TRANSFORM(THIS.DATASESSIONID) + ;
          ", Session1's datasession = " + ;
          TRANSFORM(THIS.session1.DATASESSIONID)

        .TOP = THIS.HEIGHT / 2 - .HEIGHT / 2
        .LEFT = THIS.WIDTH / 2 - .WIDTH / 2
      Endwith
    Endif
  Endproc

  Procedure DESTROY
    Clear EVENTS
  Endproc

Enddefine


Define CLASS clsDataSession AS SESSION
  DataSession = 2
Enddefine
 
Hi,

Thanks all 2 for your reply.

For Mike
The behaviour you described is what I would expect. A session object is designed to be used as a free-standing object which manages its own datasession. I can't think of a good reason to add it to a container, but if you did do so, it seems reasonable that the datasession would be governed by that of the container.

The sample was only for test it.
I'm creating a Telnet Server with Vfp based on winsock to connect with a lot of wireless barcode terminals.
My app create a new container for each connection in which I add some controls to connect with AS400 and read/write informations on it. Was convenient for me to use AddObject to use .Parent to refer to some informations.
Well, now I know I have to use CreateObject and refer to it in other way.
Thank you very much.

Andrea C.P.
Italy [atom] Turin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top