Compile function Get_Key_Controls(Window)

************************************************************************************************
*
* This program is proprietary and is not to be used by or disclosed to others, nor is it to be
* copied without written permission from SRP Computer Solutions unless used exclusively within
* the context of the licensed user's proprietary application or within a deployed runtime
* generated by the licensed user
*
* Name       :  Get_Key_Controls
*
* Description:  Returns a list of key controls for the window
*
* Notes      :	
*
* Parameters
*   Window 		[in]  -- The window needing the FOCUS change
*	KeyList	   [out]  -- @FM delimited list of key controls sorted in PART order
*
* History (Date, Initials, Notes)
*   09/11/99  dmb   Original programmer
*	12/13/05  dmb	Assigned Window to @Window if it is unassigned
*
************************************************************************************************

$insert APP_INSERTS

Declare function Get_Property
Declare subroutine V119

If Assigned(Window) else Window = @Window

* Get list of all controls
CtrlList = Get_Property(Window, "CTRLMAP")
Convert @FM to @RM in CtrlList
* Get field positions of all controls
PosList = Get_Property(CtrlList, Str("POS":@RM, Count(CtrlList, @RM)):"POS")
* Build list of keys
KeyList = ""
Loop
	Locate "0" in PosList using @RM Setting Pos else Pos = 0
While Pos
	KeyList := Field(CtrlList, @RM, Pos):@RM
	PosList = Field(PosList, @RM, Pos+1, 999)
	CtrlList = Field(CtrlList, @RM, Pos+1, 999)
Repeat
KeyList[-1, 1] = ""
NumKeyCtrls = Count(KeyList, @RM) + (KeyList NE "")
If NumKeyCtrls GT 1 then
	Props = Str("PART":@RM, NumKeyCtrls-1):"PART"
	Parts = Get_Property(KeyList, Props)
	Convert @RM to @FM in KeyList
	Convert @RM to @FM in Parts
	Work = ""
	For Loop = 1 to NumKeyCtrls
		Work := Parts<Loop>:@FM:KeyList<Loop>:@RM
	Next Loop
	V119("S", "", "A", "R", Work, "")
	For Loop = 1 to NumKeyCtrls
		KeyList<Loop> = Field(Work, @RM, Loop)<2>
	Next Loop
end

Return KeyList
