Re: How to determine if a SET exists?

2016-10-19 Thread Tom Dillon
Kirk Brooks wrote:

>That being said I think the best solution for me right now is the error 39
>trap Jeremy and David and some others have suggested.

Just FYI, the Save Set command saves the specified set to a document unless the 
set does not exist, in which case no document is created, no error is generated 
and OK is set to 1. So, you could call Save Set and test for the document's 
existence to determine if the set exists, then delete the document.

Probably more work than testing for Error 39, but it's there.

-- 
   --
   Tom Dillon   825 N. 500 W.
   DataCraft   Moab, UT 84532
   tomdil...@datacraft-inc.com   720/209-6502
   --
 Life is a great big canvas; throw all the paint you can at it.
  --- Danny Kaye
   --


**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: How to determine if a SET exists?

2016-10-18 Thread Kirk Brooks
David,
On Tue, Oct 18, 2016 at 5:12 PM, David Adams  wrote:

> I thought that I already had a Set_Exists("Set_Name") : Boolean
> function...but I didn't. Thanks for the conversation,

​Almost always ready to converse. And "yeah, I thought I had that too"
until I tried to find it.

Thanks for actually testing out a solution.​

-- 
Kirk Brooks
San Francisco, CA
===
**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: How to determine if a SET exists?

2016-10-18 Thread John DeSoi
I thought about this as a feature request, but I have not officially posted it 
yet. It would be really useful if 4D could call a method of your choosing when 
an object goes out of scope (no more references to it). Lots of other languages 
have something like this which allows you to ensure that resources are freed 
when an object is no longer needed. Then you could attach sets, named 
selections, and other types of resources to the object and clean them up when 
the object is no longer referenced.


John DeSoi, Ph.D.


> On Oct 18, 2016, at 5:52 PM, Sujit Shah  wrote:
> 
> It is so easy to lose track of which objects have been created / cleared.

**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: How to determine if a SET exists?

2016-10-18 Thread David Adams
I thought that I already had a Set_Exists("Set_Name") : Boolean
function...but I didn't. Thanks for the conversation, this code works in
V13 (what I have open right now):

C_BOOLEAN($0;$exists)
C_TEXT($1;$set_name)

$set_name:=$1

Error:=0

ErrorHandler_Install ("ErrorHandler_SuppressError")

C_BOOLEAN($is_in_set)
$is_in_set:=Is in set($set_name)

ErrorHandler_InstallPrevious

$exists:=Error=0 // You could test for error 39 to be a bit more specific.

$0:=$exists

...this assumes that you install a valid error handler, otherwise you'll
get some other error...
**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: How to determine if a SET exists?

2016-10-18 Thread Douglas von Roeder
On Tue, Oct 18, 2016 at 10:46 AM, Kirk Brooks  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:4d_tech-unsubscr...@lists.4d.com
**

Re: How to determine if a SET exists?

2016-10-18 Thread Kirk Brooks
Randy,
That was my first thought too. In this case I need to know if the set has
been attempted to be created.

But maybe not. Have to work with what I have I suppose.

On Tue, Oct 18, 2016 at 8:16 AM, Randy Engle <4d.l...@xc2.us> wrote:

> Kirk,
>
> It's not 100% what you are looking for, but I'm pretty sure you can do a
> "Records in Set"
>
> $0:=Records in Set("MySet")
>
> If the set does not exist, it will return 0.
>
> Of course this is also true if the set exists with zero records in it.
>  ;-)
>
-- 
Kirk Brooks
San Francisco, CA
===
**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: How to determine if a SET exists?

2016-10-18 Thread Douglas von Roeder
Kirk:

IIRC, activate an error handler prior to calling the command that uses the
set.

--
Douglas von Roeder
949-336-2902

On Tue, Oct 18, 2016 at 8:16 AM, Randy Engle <4d.l...@xc2.us> wrote:

> Kirk,
>
> It's not 100% what you are looking for, but I'm pretty sure you can do a
> "Records in Set"
>
> $0:=Records in Set("MySet")
>
> If the set does not exist, it will return 0.
>
> Of course this is also true if the set exists with zero records in it.
>  ;-)
>
> Randy Engle
> XC2 Software LLC
>
> -Original Message-
> From: 4D_Tech [mailto:4d_tech-boun...@lists.4d.com] On Behalf Of Kirk
> Brooks
> Sent: Tuesday, October 18, 2016 7:35 AM
> To: 4D iNug Technical <4d_tech@lists.4d.com>
> Subject: How to determine if a SET exists?
>
> Hi all,
> Is there a way to determine if a set exists? So far the only thing I've
> come up with requires keeping track of them as they are created. This is OK
> but unverifiable.
>
> It would be nice to have the equivalent of the 'Is a list' function.
>
>
>
> **
> 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:4d_tech-unsubscr...@lists.4d.com
> **
>
**
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:4d_tech-unsubscr...@lists.4d.com
**

RE: How to determine if a SET exists?

2016-10-18 Thread Randy Engle
Kirk,

It's not 100% what you are looking for, but I'm pretty sure you can do a 
"Records in Set"

$0:=Records in Set("MySet")

If the set does not exist, it will return 0.

Of course this is also true if the set exists with zero records in it.   ;-)

Randy Engle
XC2 Software LLC

-Original Message-
From: 4D_Tech [mailto:4d_tech-boun...@lists.4d.com] On Behalf Of Kirk Brooks
Sent: Tuesday, October 18, 2016 7:35 AM
To: 4D iNug Technical <4d_tech@lists.4d.com>
Subject: How to determine if a SET exists?

Hi all,
Is there a way to determine if a set exists? So far the only thing I've come up 
with requires keeping track of them as they are created. This is OK but 
unverifiable.

It would be nice to have the equivalent of the 'Is a list' function.



**
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:4d_tech-unsubscr...@lists.4d.com
**

How to determine if a SET exists?

2016-10-18 Thread Kirk Brooks
Hi all,
Is there a way to determine if a set exists? So far the only thing I've
come up with requires keeping track of them as they are created. This is OK
but unverifiable.

It would be nice to have the equivalent of the 'Is a list' function.

-- 
Kirk Brooks
San Francisco, CA
===
**
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:4d_tech-unsubscr...@lists.4d.com
**