Académique Documents
Professionnel Documents
Culture Documents
The application class possesses everything about the house everything necessary for its
construction and its appearance.
In some respects a simple application class can appear to be similar to a function:
1. You declare a function in PeopleCode to make it ready to be used. With an application class
you import and then create the class to make it ready to be used.
2. You then call that function to do some work by passing parameters to the function. With an
application class, you either pass in parameters, or you set object properties.
3. After the function is complete, work has been done, and has possibly returned a value. With an
application class, work was performed by returning a value or by changing the value of one of its
properties.
Basic Illustration
You will create a function and an application class to do the same thing in order to highlight the
differences.
Add two numbers together and receive the sum.
Create a Function
Local number &c;
Function AddNumbers(&a As number, &b As number) Returns number
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
/* Add numbers &a and &b together
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
&c = &a + &b;
Messagebox (0, "", 0, 0, "My Result is: " | &c);
Return &c;
End-Function;
class MyFormulaCruncher
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
/* The following line is known as the constructor. The method will
*/
/*
have the same name as the application class name.
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
method MyFormulaCruncher();
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
*/
*/
/* Here is the method that will perform the addition of &a and &b
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
method AddNumbers(&a As number, &b As number) Returns number;
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
*/
*/
*/
*/
/* Here is the method that will perform the addition by setting object
/*
properties and read the property MySum to determine the result after
/*
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
method AddNumbers2();
*/
*/
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/* Allow a property to be read and write by not setting to readonly
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
property number FirstNumber;
property number SecondNumber;
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
*/
*/
*/
/* Since this is readonly, if you try to set this value you will get a
/*
compile error
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
property number MySum readonly;
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
*/
*/
*/
*/
/* All properties and methods that are listed after the key word
/*
/*
/*
/*
invisible/hidden
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
protected
property number MySumProtected;
end-class;
method MyFormulaCruncher
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
/* You do not need to do any initial setup - nothing to do
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
end-method;
method AddNumbers
/+ &a as Number, +/
/+ &b as Number +/
/+ Returns Number +/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
/* Do not alter or create your own lines that start with /+
*/
*/
*/
*/
*/
when the application class is saved and the method has parameters
/*
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Local number &c;
&c = &a + &b;
MessageBox(0, "", 0, 0, "My AddNumbers result is: " | &c);
Return &c;
end-method;
method AddNumbers2
&MySum = &FirstNumber + &SecondNumber;
&MySumProtected = &FirstNumber + &SecondNumber;
*/
*/
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/* property &MySumProtected is available with in this app class
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MessageBox(0, "", 0, 0, "My AddNumbers2 result is: " | &MySumProtected);
end-method;
/*
parameters, but will use the two object properties
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
&My_Nbr.AddNumbers2();
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
/* This method is also different than the other in that it is not returning
*/
/*
a value. Instead, the method is setting another class property that can
*/
/*
be read into a variable
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
&Result = &My_Nbr.MySum;
/*
*/
/*
*/
/*
*/
/*
*/
/*
*/
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Attempting to use this property would result in a compile error since it
is not accessible outside the application class
&Result = &My_Nbr.MySumProtected
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!