Form VL_SAM099: Space Built-in Function

LANSA

Form VL_SAM099: Space Built-in Function
Name: VL_SAM099

Description: The following RDMLX form demonstrates the most fundamental use of the SPACE built-in functions.
FUNCTION OPTIONS(*DIRECT);
BEGIN_COM HEIGHT(314) LEFT(77) TOP(179) WIDTH(846);
;
Define #SpaceName *char 20;
Define #TestSize RefFld(#Std_Num) Default(1000) ;
;
Define #EmpMaxKey RefFld(#date) Length(7) decimals(0) edit_code(4) default(0);
Define #EmpMaxChr *char 7 to_Overlay(#EmpMaxKey);
Define #HitCount RefFld(#Std_Num);
Define #EmpNote RefFld(#Std_TextL);
Define #EmpKey RefFld(#EmpMaxKey);
;
Define #SpaceRC *Char 2 ;
Def_Cond *Okay '#SpaceRC = OK' ;
;
Define #EmpCount RefFld(#Std_Num);
Def_List #Emps (#GiveName #SurName) type(*Working) Entrys(9999) Counter(#EmpCount);
;
DEFINE_COM CLASS(#PRIM_STBR) NAME(#STBR_1) DISPLAYPOSITION(9) HEIGHT(25) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(5) TABSTOP(False) TOP(262) WIDTH(838);
DEFINE_COM CLASS(#STD_NUM.Visual) NAME(#EXAMCOUNT) CAPTION('Total Example Employees') DISPLAYPOSITION(10) LABELTYPE(Caption) LEFT(24) MARGINLEFT(145) PARENT(#COM_OWNER) READONLY(True) TABPOSITION(6) TABSTOP(False) TOP(16) VISUALSTYLE(#VS_NOREAD) WIDTH(216);
DEFINE_COM CLASS(#STD_NUM.Visual) NAME(#VEMPKEY) CAPTION('Employee Number to Locate ') DISPLAYPOSITION(1) LABELTYPE(Caption) LEFT(24) MARGINLEFT(145) PARENT(#COM_OWNER) TABPOSITION(1) TOP(53) WIDTH(217);
DEFINE_COM CLASS(#GIVENAME.Visual) NAME(#VGIVENAME) DISPLAYPOSITION(11) LEFT(24) MARGINLEFT(145) PARENT(#COM_OWNER) READONLY(True) TABPOSITION(7) TABSTOP(False) TOP(90) VISIBLE(False) VISUALSTYLE(#VS_NOREAD);
DEFINE_COM CLASS(#SURNAME.Visual) NAME(#VSURNAME) DISPLAYPOSITION(12) LEFT(24) MARGINLEFT(145) PARENT(#COM_OWNER) READONLY(True) TABPOSITION(8) TABSTOP(False) TOP(127) VISIBLE(False) VISUALSTYLE(#VS_NOREAD) WIDTH(326);
DEFINE_COM CLASS(#STD_NUM.Visual) NAME(#VHITCOUNT) CAPTION('Number of Lookups') DISPLAYPOSITION(13) LABELTYPE(Caption) LEFT(24) MARGINLEFT(145) PARENT(#COM_OWNER) READONLY(True) TABPOSITION(9) TABSTOP(False) TOP(164) VISIBLE(False) VISUALSTYLE(#VS_NOREAD) WIDTH(209);
DEFINE_COM CLASS(#STD_TEXTL.Visual) NAME(#VEMPNOTE) CAPTION('Notes for this Employee') DISPLAYPOSITION(2) LABELTYPE(Caption) LEFT(24) MARGINLEFT(145) PARENT(#COM_OWNER) TABPOSITION(2) TOP(200) VISIBLE(False) WIDTH(425);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_1) CAPTION('Create more Employees') DISPLAYPOSITION(3) LEFT(456) PARENT(#COM_OWNER) TABPOSITION(3) TOP(16) WIDTH(136);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_2) CAPTION('Count Details') DISPLAYPOSITION(4) LEFT(456) PARENT(#COM_OWNER) TABPOSITION(4) TOP(64) WIDTH(137);
;
DEFINE_COM CLASS(#PRIM_STTC) NAME(#TRI001) DISPLAYPOSITION(8) DRAWTYPE(TriangleLeft) HEIGHT(26) LEFT(595) LINEWIDTH(3) PARENT(#COM_OWNER) TABPOSITION(16) TABSTOP(False) TOP(16) VISIBLE(False);
DEFINE_COM CLASS(#PRIM_LABL) NAME(#TXT001) CAPTION('Use this button to add approximately 1000 more employees into the space object ') DISPLAYPOSITION(17) HEIGHT(43) LEFT(652) PARENT(#COM_OWNER) TABPOSITION(17) TABSTOP(False) VISIBLE(False) WIDTH(181);
DEFINE_COM CLASS(#PRIM_STTC) NAME(#TRI002) DISPLAYPOSITION(7) DRAWTYPE(TriangleLeft) HEIGHT(26) LEFT(595) LINEWIDTH(3) PARENT(#COM_OWNER) TABPOSITION(12) TABSTOP(False) TOP(64) VISIBLE(False);
DEFINE_COM CLASS(#PRIM_LABL) NAME(#TXT002) CAPTION('Use this button to read and count details of all the employees currently in the space object') DISPLAYPOSITION(16) HEIGHT(43) LEFT(652) PARENT(#COM_OWNER) TABPOSITION(15) TABSTOP(False) TOP(59) VISIBLE(False) WIDTH(181);
DEFINE_COM CLASS(#PRIM_STTC) NAME(#TRI003) DISPLAYPOSITION(6) DRAWTYPE(TriangleLeft) HEIGHT(26) LEFT(456) LINEWIDTH(3) PARENT(#COM_OWNER) TABPOSITION(11) TABSTOP(False) TOP(195) VISIBLE(False);
DEFINE_COM CLASS(#PRIM_LABL) NAME(#TXT003) CAPTION('These are the employee notes. You can change these and if you come back to the employee later the changes will be remembered. Every single keystroke you make changing the notes causes the employee''s space object entry to be updated.') DISPLAYPOSITION(15) HEIGHT(58) LEFT(514) PARENT(#COM_OWNER) TABPOSITION(14) TABSTOP(False) TOP(182) VISIBLE(False) WIDTH(318);
DEFINE_COM CLASS(#PRIM_STTC) NAME(#TRI004) DISPLAYPOSITION(5) DRAWTYPE(TriangleLeft) HEIGHT(20) LEFT(242) LINEWIDTH(3) PARENT(#COM_OWNER) TABPOSITION(10) TABSTOP(False) TOP(54) VISIBLE(False) WIDTH(31);
DEFINE_COM CLASS(#PRIM_LABL) NAME(#TXT004) CAPTION('This is the employee number. It is a number in the range one to the total shown above. Every keystroke you make entering the employee number causes the employee''s entry in the space object to located and updated.') DISPLAYPOSITION(14) HEIGHT(81) LEFT(276) PARENT(#COM_OWNER) TABPOSITION(13) TABSTOP(False) TOP(6) VISIBLE(False) WIDTH(177);
DEFINE_COM CLASS(#PRIM_TIMR) NAME(#TIMER) INTERVAL(0);
;
EVTROUTINE handling(#com_owner.Initialize);
* ;
* Make a unique space name for this component and set the form caption ;
* ;
Use TConcat (*component '.EMP') (#SpaceName);
SET #com_owner caption(*component_desc);
* ;
* Fill list EMPS with employee details to be used as test data;
* ;
Message 'Loading employee source data from PSLMST' Type(*Status);
Select (#GiveName #SurName) From_File(PslMst);
Add_Entry #Emps;
EndSelect ;
* ;
* Example won't work if there is no data in the empoyee file at all;
* ;
If_null #EmpCount;
Abort 'No employees exist in PSLMST .... example code would not execute correctly';
Endif ;
* ;
* Now define the space ;
* ;
Use Create_Space (#SpaceName);
Use Define_Space_Cell (#SpaceName EmpKey Key) ;
Use Define_Space_Cell (#SpaceName GiveName) ;
Use Define_Space_Cell (#SpaceName SurName) ;
Use Define_Space_Cell (#SpaceName HitCount) ;
Use Define_Space_Cell (#SpaceName EmpNote) ;
* ;
* Fill it with the specified number of test cases ;
* ;
Invoke #Com_Owner.CreateMoreEmployees;
* ;
* Now ready for work;
* ;
Set #vEmpKey Value(5);
Invoke #Com_Owner.LocateEmployee;
Set #Timer Interval(300);
Message 'Ready';
* ;
ENDROUTINE ;
;
MthRoutine CreateMoreEmployees;
Message 'Creating Employee Test Items' Type(*Status);
DoWhile '#EmpMaxKey < #TestSize';
SelectList #Emps;
Change #EmpMaxKey '#EmpMaxKey + 1';
Use BConcat (#GiveName #SurName '-' #EmpMaxChr) (#EmpNote);
Use Insert_in_Space (#SpaceName #EmpMaxKey #GiveName #SurName 0 #EmpNote);
EndSelect ;
EndWhile ;
Change (#ExamCount #TestSize) #EmpMaxKey;
Invoke #Com_Owner.HideEmployee;
EndRoutine ;
;
MthRoutine MakeEmployeeVisible;
Set (#vGiveName #vSurName #vHitCount #vEmpNote) Visible(True) ;
Set (#Txt003 #Tri003) Visible(#Txt001.Visible);
EndRoutine ;
;
MthRoutine HideEmployee;
Set (#vGiveName #vSurName #vHitCount #vEmpNote) Visible(False) ;
Set (#Txt003 #Tri003) Visible(False);
Set #vEmpKey Value(0);
Invoke #vEmpKey.SetFocus ;
EndRoutine ;
;
EVTROUTINE Handling(#com_owner.Closing);
Use Destroy_Space (#SpaceName);
EndRoutine ;
* ;
* Handle Change to the requested employee number;
* ;
EVTROUTINE HANDLING(#vEmpKey.Changed) ;
Invoke #Com_Owner.LocateEmployee;
ENDROUTINE ;
* ;
* Handle an Employee Key Changed;
* ;
MthRoutine LocateEmployee;
if '(#vEmpKey >= 1) and (#vEmpKey <= #TestSize)';
Use Fetch_in_Space (#SpaceName #vEmpKey) (#SpaceRc #vEmpKey #vGiveName #vSurName #vHitCount #vEmpNote);
Change #vHitCount '#vHitCount + 1';
Use Update_in_Space (#SpaceName #vEmpKey #vGiveName #vSurName #vHitCount #vEmpNote);
Invoke #Com_Owner.MakeEmployeeVisible ;
else ;
Invoke #Com_Owner.HideEmployee ;
Message 'Employee does not exist';
endif ;
EndRoutine ;
* ;
* Handle any changes to Employee Notes ;
* ;
EVTROUTINE HANDLING(#vEmpNote.Changed) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
Change #vHitCount '#vHitCount + 1';
Use Update_In_Space (#SpaceName #vEmpKey #vGiveName #vSurName #vHitCount #vEmpNote);
ENDROUTINE ;
* ;
* Handle a request to create more test employees ;
* ;
EVTROUTINE HANDLING(#PHBN_1.Click);
Change #TestSize '#TestSize + 1000' ;
Invoke #Com_Owner.CreateMoreEmployees;
ENDROUTINE ;
* ;
* Handle a request to count employee details;
* ;
EVTROUTINE HANDLING(#PHBN_2.Click);
Define #EmpTotal RefFld(#Std_Num);
Define #TotalHits RefFld(#Std_Num);
* ;
* Note how none of the fields retreived from the space object are visual (ie: on the form).;
* This has a major impact on performance because including visual components slows;
* down the logic as the data content has to be drawn/queued for the visual context. ;
* ;
Change (#EmpTotal #TotalHits) 0 ;
Use Select_in_Space (#SpaceName) (#SpaceRc #EmpKey #GiveName #SurName #HitCount);
DoWhile *okay ;
Change #EmpTotal '#EmpTotal + 1';
Change #TotalHits '#TotalHits + #HitCount' ;
Use SelectNext_in_Space (#SpaceName) (#SpaceRc #EmpKey #GiveName #SurName #HitCount);
EndWhile ;
;
Set #Timer Interval(0) ;
Use Message_Box_Add ('Total Employees :' #EmpTotal);
Use Message_Box_Add ('Total Hits an all Employees :' #TotalHits );
Use Message_Box_Show;
Set #Timer Interval(10000) ;
;
Invoke #Com_Owner.HideEmployee ;
;
ENDROUTINE ;
* ;
* Handle the Timer ;
* ;
EVTROUTINE HANDLING(#TIMER.Tick) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
If '#TXT001.Visible = True';
Set (#TXT001 #TRI001 #TXT002 #TRI002 #TXT003 #TRI003 #TXT004 #TRI004) Visible(False);
Set #Timer Interval(20000);
Else ;
Set (#TXT001 #TRI001 #TXT002 #TRI002 #TXT004 #TRI004) Visible(True);
Set (#TXT003 #TRI003) Visible(#vEmpNote.Visible);
Set #Timer Interval(40000);
Endif ;
EndRoutine ;
;
;
END_COM ;