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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to tranfer the object handler between two form?

Status
Not open for further replies.

oivluf

Programmer
Jul 17, 2003
2
0
0
IT
I have a project with two forms.

In the first form, I create an object instance from my own class:

INVOKE my-class-name "NEW" RETURNING obj-ref.

Now i need to perform some action in a child form, and
I need to use the same object, so I need to know how to
transfer the handler:

01 obj-ref USAGE OBJECT REFERENCE my-class-name.

from the first form to the second.

Any Ideas?
 
If you use PowerCOBOL you can create your object as a control. Then register it in your system, and put it as a normal control on the main form (adding with custom control), open child form with INVOKE CHILD_NAME "Activate", and pass data between the forms.
I do not know if this is helpful for you.
fsccdm
 
OK. I am successful to solve my problem!

My problem:

I need to create a class that manage the DataBase
connection for my applications.
So I need to creat it one time, on program start, and share this
object-instance inside my run unit and between forms.

In this test-class I'm trying to use the MyVbQL.dll to connect to
MySQL data_base with InnoDB that support the row-level locking.

In a previous test where I have used the ESQL, the problem already
had been resolved passing the connection name between forms with
EXTERNAL clause and set it with the "SET CONNECTION", but
unfortunately the FJ don't perform the FETCH PRIOR, FIRST, LAST
on cursors.


Solution:

implement the "Singleton" when create a new object-instance of the class.

How to:

1. create a new class called "singleton" that inherit FJBASE.
2. put the "singleton" class inside the repository of the class
that you want instantiate only one time.

That's all.

The "singleton" class:

**************************************************

IDENTIFICATION DIVISION.
CLASS-ID. SINGLETON INHERITS FJBASE.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
REPOSITORY.
CLASS FJBASE.
FACTORY.
DATA DIVISION.

WORKING-STORAGE SECTION.
01 CTRL-OBJ OBJECT REFERENCE SELF.

PROCEDURE DIVISION.

METHOD-ID. NEW OVERRIDE.
DATA DIVISION.

LINKAGE SECTION.
01 L-CTRL-OBJ OBJECT REFERENCE SELF.

PROCEDURE DIVISION RETURNING L-CTRL-OBJ.

IF CTRL-OBJ = NULL
SET CTRL-OBJ L-CTRL-OBJ TO SUPER :: "NEW"
INVOKE CTRL-OBJ "INIT"
ELSE
SET L-CTRL-OBJ TO CTRL-OBJ.

END METHOD NEW.
END FACTORY.
END CLASS SINGLETON.
**************************************************


This small class has one variable that is a pointer to itself.

In the implementation of the "new" method, there is a test that checks if
the variable has been initialized, and if not, creates a new instance.

This way of initialization in the control block, means that the Singleton instance
is initialized, or created, only on the first invoke to the "new" method.

In this way I can invoke the "new" method on my own class in the parent form and
"create" the instance, and invoke the "new" method again in the sub form (child)
and instantiate the same object.

I hope that it can be useful.

Fulvio.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top