pmahesha
13 years agoOccasional Contributor
Storing Object references in global variables
Hello,
I have one issue with storing object references globally. I used a class and object to store certain parameters to test series of text boxes. All parameters are retained properly except the reference to the object. I wanted to store the reference to the
text box object inside my object variable so that I can write scripts to test all the text fields in a loop.
Here is my program:
// Step1: Define global Object for storing properties of a text box.
var w;
// Open the Window
Sys.Process("java").SwingObject("ImageViewerDisplay", "Intra*", 0, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JPanel", "", 0).SwingObject("JButton", "", 0).ClickButton();
// Create New object ( which is Global to this file). Class "TextFieldClass" is already declared using visual method.
PatientNumObj=ODT.Classes.New("TextFieldClass");
// Get the reference to the text field and store it as FieldAddress
w=Sys.Process("java").SwingObject("ct", "", -1, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JScrollPane", "", 0).SwingObject("JViewport", "", 0).SwingObject("JTabbedPane", "PATIENT INFO", 0).SwingObject("JPanel", "** ADD PATIENT DETAILS **", 0).SwingObject("JTextField", "", 0);
PatientNumObj.FieldAddress=w;
PatientNumObj.FieldName="Patient ID";
PatientNumObj.MinLength=1;
PatientNumObj.MaxLength=20;
PatientNumObj.MandatoryTrueOrFalse="TRUE";
//PatientNumObj.ClickCoordinate="26,8";
PatientNumObj.FieldType="NUMERIC";
PatientNumObj.FirstChr="NUMERIC"
PatientNumObj.Case="BOTH"
// Then I define new function in the same file at the end.
function test()
{
Log.Message(PatientNumObj.MaxLength); // This prints correctly.
Log.Message(PatientNumObj.FieldType); //This prints the values correctly.
var mykeys="Mahesha";
// Key in the name
PatientNumObj.FieldAddress.Keys(mykeys);
}
When I run, I get the results as:
The button was clicked with the left mouse button.
20
NUMERIC
Keyboard input.
Note that "Mahesha" is keyed in properly in the respective text box.
But If I close the window and reload, this does not work. We get error message
var w;
// Open the Window
Sys.Process("java").SwingObject("ImageViewerDisplay", "Intra SKAN*", 0, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JPanel", "", 0).SwingObject("JButton", "", 0).ClickButton();
// Create New object
PatientNumObj=ODT.Classes.New("TextFieldClass");
// Get the reference to the text field
w=Sys.Process("java").SwingObject("ct", "", -1, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JScrollPane", "", 0).SwingObject("JViewport", "", 0).SwingObject("JTabbedPane", "PATIENT INFO", 0).SwingObject("JPanel", "** ADD PATIENT DETAILS **", 0).SwingObject("JTextField", "", 0);
PatientNumObj.FieldAddress=w;
PatientNumObj.FieldName="Patient ID";
PatientNumObj.MinLength=1;
PatientNumObj.MaxLength=20;
PatientNumObj.MandatoryTrueOrFalse="TRUE";
//PatientNumObj.ClickCoordinate="26,8";
PatientNumObj.FieldType="NUMERIC";
PatientNumObj.FirstChr="NUMERIC"
PatientNumObj.Case="BOTH"
// Close the window
Sys.Process("java").SwingObject("ct", "", -1, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("MetalTitlePane", "", 0).SwingObject("JButton", "Close", 0).ClickButton();
function test()
{
// Again Open the Window
Sys.Process("java").SwingObject("ImageViewerDisplay", "Intra*", 0, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JPanel", "", 0).SwingObject("JButton", "", 0).ClickButton();
Log.Message(PatientNumObj.MaxLength);
Log.Message(PatientNumObj.FieldType);
var mykeys="Mahesha";
// Key in the name
PatientNumObj.FieldAddress.Keys(mykeys);
}
Result:
The button was clicked with the left mouse button.
The button was clicked with the left mouse button.
The button was clicked with the left mouse button.
20
NuMERIC
The '' window is invisible and cannot be activated.
The last line in the result is error. Also "Mahesha" is not typed in the text field referenced by PatientNumObj.FieldAddress.
My second question:
How do I store the reference to an object without really opening the corresponding window? In the above code, we can see that window was opened just to ensure that we do not get error message for following.
w=Sys.Process("java").SwingObject("ct", "", -1, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JScrollPane", "", 0).SwingObject("JViewport", "", 0).SwingObject("JTabbedPane", "PATIENT INFO", 0).SwingObject("JPanel", "** ADD PATIENT DETAILS **", 0).SwingObject("JTextField", "", 0);
PatientNumObj.FieldAddress=w;
Is there a method to store the object reference, without opeining the respective window?
I hope someone will be able to help me in this regard,
I have one issue with storing object references globally. I used a class and object to store certain parameters to test series of text boxes. All parameters are retained properly except the reference to the object. I wanted to store the reference to the
text box object inside my object variable so that I can write scripts to test all the text fields in a loop.
Here is my program:
// Step1: Define global Object for storing properties of a text box.
var w;
// Open the Window
Sys.Process("java").SwingObject("ImageViewerDisplay", "Intra*", 0, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JPanel", "", 0).SwingObject("JButton", "", 0).ClickButton();
// Create New object ( which is Global to this file). Class "TextFieldClass" is already declared using visual method.
PatientNumObj=ODT.Classes.New("TextFieldClass");
// Get the reference to the text field and store it as FieldAddress
w=Sys.Process("java").SwingObject("ct", "", -1, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JScrollPane", "", 0).SwingObject("JViewport", "", 0).SwingObject("JTabbedPane", "PATIENT INFO", 0).SwingObject("JPanel", "** ADD PATIENT DETAILS **", 0).SwingObject("JTextField", "", 0);
PatientNumObj.FieldAddress=w;
PatientNumObj.FieldName="Patient ID";
PatientNumObj.MinLength=1;
PatientNumObj.MaxLength=20;
PatientNumObj.MandatoryTrueOrFalse="TRUE";
//PatientNumObj.ClickCoordinate="26,8";
PatientNumObj.FieldType="NUMERIC";
PatientNumObj.FirstChr="NUMERIC"
PatientNumObj.Case="BOTH"
// Then I define new function in the same file at the end.
function test()
{
Log.Message(PatientNumObj.MaxLength); // This prints correctly.
Log.Message(PatientNumObj.FieldType); //This prints the values correctly.
var mykeys="Mahesha";
// Key in the name
PatientNumObj.FieldAddress.Keys(mykeys);
}
When I run, I get the results as:
The button was clicked with the left mouse button.
20
NUMERIC
Keyboard input.
Note that "Mahesha" is keyed in properly in the respective text box.
But If I close the window and reload, this does not work. We get error message
var w;
// Open the Window
Sys.Process("java").SwingObject("ImageViewerDisplay", "Intra SKAN*", 0, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JPanel", "", 0).SwingObject("JButton", "", 0).ClickButton();
// Create New object
PatientNumObj=ODT.Classes.New("TextFieldClass");
// Get the reference to the text field
w=Sys.Process("java").SwingObject("ct", "", -1, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JScrollPane", "", 0).SwingObject("JViewport", "", 0).SwingObject("JTabbedPane", "PATIENT INFO", 0).SwingObject("JPanel", "** ADD PATIENT DETAILS **", 0).SwingObject("JTextField", "", 0);
PatientNumObj.FieldAddress=w;
PatientNumObj.FieldName="Patient ID";
PatientNumObj.MinLength=1;
PatientNumObj.MaxLength=20;
PatientNumObj.MandatoryTrueOrFalse="TRUE";
//PatientNumObj.ClickCoordinate="26,8";
PatientNumObj.FieldType="NUMERIC";
PatientNumObj.FirstChr="NUMERIC"
PatientNumObj.Case="BOTH"
// Close the window
Sys.Process("java").SwingObject("ct", "", -1, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("MetalTitlePane", "", 0).SwingObject("JButton", "Close", 0).ClickButton();
function test()
{
// Again Open the Window
Sys.Process("java").SwingObject("ImageViewerDisplay", "Intra*", 0, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JPanel", "", 0).SwingObject("JButton", "", 0).ClickButton();
Log.Message(PatientNumObj.MaxLength);
Log.Message(PatientNumObj.FieldType);
var mykeys="Mahesha";
// Key in the name
PatientNumObj.FieldAddress.Keys(mykeys);
}
Result:
The button was clicked with the left mouse button.
The button was clicked with the left mouse button.
The button was clicked with the left mouse button.
20
NuMERIC
The '' window is invisible and cannot be activated.
The last line in the result is error. Also "Mahesha" is not typed in the text field referenced by PatientNumObj.FieldAddress.
My second question:
How do I store the reference to an object without really opening the corresponding window? In the above code, we can see that window was opened just to ensure that we do not get error message for following.
w=Sys.Process("java").SwingObject("ct", "", -1, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JScrollPane", "", 0).SwingObject("JViewport", "", 0).SwingObject("JTabbedPane", "PATIENT INFO", 0).SwingObject("JPanel", "** ADD PATIENT DETAILS **", 0).SwingObject("JTextField", "", 0);
PatientNumObj.FieldAddress=w;
Is there a method to store the object reference, without opeining the respective window?
I hope someone will be able to help me in this regard,