On Tue, Oct 18, 2016 at 10:46 AM, Kirk Brooks <[email protected]> wrote:
> Doug,
> I thought about that too. But then I'm fiddling around with the current
> selection.
>
> I guess there's no issue with simply re-creating a set if it has no records
> in it..
>
Kirk:
Agreed.
I just ran a bit of code (V12) to understand what errors are thrown using
set commands.
Use set throws error 39 if the referenced set does not exist. However,
Records in set returns 0 *without* throwing an error. Hmm…
Your point about recreating the set is valid but that also sidesteps the
possibility that you have a "bug" in your code (a logic error vs syntax),
right?
One way to get around the "lack of a stack" is to use code to create one or
many sets and return an Object with metadata about the set. To create named
selections, I use an Object that's filled with default values by
*SEL_BaseClass_Init.
*The Object can be used in the method in which it's created, passed as
a parameter, or added to the Object as an item.
This is from the code in the *_Init* method:
C_TEXT($scope_T)
SEL_Scope_Set ($h_;SEL_Scope_Local)
//SEL_Scope_Set ($h_;SEL_Scope_IP)
//SEL_Scope_Set ($h_;SEL_Scope_Process)
C_TEXT($action_T)
//SEL_Action_Set ($h_;SEL_Action_Cut)
SEL_Action_Set ($h_;SEL_Action_Copy)
ARRAY LONGINT($tableNumber_AL;0)
OT_Array_Set ($h_;"$tableNumber_AL";->$tableNumber_AL)
//Do not assign a "default" value
//SEL_TablePtr_Assign ($h_;<>pNil)
//<>pNil:=SEL_TablePtr_Get($h_)
C_BOOLEAN($clearAfterUse_F)
SEL_ClearAfterUse_Set ($h_;True)
//<>BooleanNil:=SEL_ClearAfterUse_Get($h_)
SEL_RIS_Set ($h_;<>LongintNil)
//<>LongintNil:=SEL_Ris_Get($h_)
SEL_SelRecNum_Set ($h_;<>LongintNil)
//<>LongintNil:=SEL_SelRecNum_Get($h_)
SEL_SelSize_Set ($h_;<>LongintNil)
//<>LongintNil:=SEL_SelSize_Get($h_)
SEL_FirstSelRecNum_Set ($h_;<>LongintNil)
//<>LongintNil:=SEL_FirstSelRecNum_Get($h_)
SEL_LastSelRecNum_Set ($h_;<>LongintNil)
//<>LongintNil:=SEL_LastSelRecNum_Get($h_)
$0:=$h_
When this code completes execution, I have an Object with the defaults of
cutting the current selection and creating a local named selection.
I add pointers to the tables in which a named selection will be created
and then call *SEL_CurrentSel_Create*
Here's the test code for *SEL_CurrentSel_Create*:
ALL RECORDS([Contacts])
REDUCE SELECTION([Contacts];10)
ALL RECORDS([Proposals])
REDUCE SELECTION([Proposals];10)
//OT Clear (<>SEL_Handle)
//Modify this code to use the base class
C_LONGINT($selHandle_L)
$selHandle_L:=*OT_MasterObject_Return* ("SEL")<===== this code calls
*SEL_BaseClass_Init*
//Default values
if(False)
*SEL_Action_Set* ($selHandle_L;SEL_Action_Copy)
*SEL_Scope_Set* ($selHandle_L;SEL_Scope_Local)
*SEL_Action_Set* ($selHandle_L;SEL_Action_Cut)
*SEL_Scope_Set* ($selHandle_L;SEL_Scope_Process)
end if
*SEL_TablePtr_Assign* ($selHandle_L;->[Contacts])
*SEL_TablePtr_Assign* ($selHandle_L;->[Proposals])
$selHandle_L :=*SEL_CurrentSel_Create* ($selHandle_L)
REDUCE SELECTION([Proposals];0)
REDUCE SELECTION([Contacts];0)
*SEL_CurrentSel_Restore* ($selHandle_L)
*OT_Object_Clear* ($selHandle_L)
//Should have 10 records in each table
REDUCE SELECTION([Proposals];0)
REDUCE SELECTION([Contacts];0)
Or, if you need to put it all on one line (!)
$selHandle_L:=*SEL_CurrentSel_Create* (*SEL_TablePtr_Assign* (
*OT_MasterObject_Return* ("SEL");->[Contacts]))
And the nice thing about using a 4D Object is that you don't have to muck
with *OT_Object_Clear* ($selHandle_L). :-)
--
Douglas von Roeder
949-336-2902
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************