Hi Chris,

What we really need is a way to access a Form Object's "Variable or
Expression".  There's a Command named "Object Get Data Source" which was
added in v14, but it only returns a Pointer if  "Variable or Expression" is
a Variable.  If it's an Expression it returns Nil.

If we could get the Expression, then we could use Evaluate Formula to
Get/Set the Value.

There's currently no 4D Command to do this directly, but you can do it
using "Form Convert to dynamic".  It's an "expensive" command, but it does
the job until 4D give us a better way.


  //Method: Object Get Expression
  //Returns the Expression / Data Source of the Form Object named $1

C_TEXT($0)  //Object Expression / Data Source
C_TEXT($1)  //Optional, Object Name.  Default = the Current Object

C_LONGINT($l_Page)
C_OBJECT($o_Form)
C_TEXT($t_ObjectName)

Case of
: (Count parameters<1)
$t_ObjectName:=OBJECT Get name(Object current)
: ($1="")
$t_ObjectName:=OBJECT Get name(Object current)
Else
$t_ObjectName:=$1
End case

If ($t_ObjectName#"")
If (Current form table=Null)
$o_Form:=FORM Convert to dynamic(Current form name)
Else
$o_Form:=FORM Convert to dynamic(Current form table->;Current form name)
End if

If ($o_Form.pages#Null)
$0:=String($o_Form.pages[FORM Get current
page].objects[$t_ObjectName].dataSource)  //The Object is most likely to be
on the Current Page, so start looking there

If ($0="")  //Not on the Current Page, so look at all Pages
For ($l_Page;0;$o_Form.pages.length-1)
If ($l_Page#FORM Get current page)  //We've already checked the Current
Page, so no need to check it again
$0:=String($o_Form.pages[$l_Page].objects[$t_ObjectName].dataSource)

If ($0#"")
$l_Page:=999
End if
End if
End for
End if
End if
End if



Ideally I'd like to have Object Get Value and Object Set Value commands.

I present to you;

---------------------------------------------------------------------------------------------------------------
  //Method: Object Set Vaule

C_TEXT($1)  //Object Name
C_VARIANT($2)  //Value

C_TEXT($t_DataSource;$t_ObjectName)

C_VARIANT(__ObjectValue)  //Required for EXECUTE FORMULA

If ($1="")
$t_ObjectName:=OBJECT Get name(Object current)
Else
$t_ObjectName:=$1
End if

If ($t_ObjectName#"")
$t_DataSource:=Object Get Expression ($t_ObjectName)

If ($t_DataSource#"")
__ObjectValue:=$2  //Params and Locals can't be used in EXECUTE FORMULA
EXECUTE FORMULA($t_DataSource+":=__ObjectValue")
End if
End if



---------------------------------------------------------------------------------------------------------------
  //Method: Object Get Vaule

C_VARIANT($0)  //Object Value
C_TEXT($1)  //Object Name.  Default = the Current Object

C_TEXT($t_DataSource;$t_ObjectName)

C_VARIANT(__ObjectValue)  //Required for EXECUTE FORMULA

Case of
: (Count parameters<1)
$t_ObjectName:=OBJECT Get name(Object current)
: ($1="")
$t_ObjectName:=OBJECT Get name(Object current)
Else
$t_ObjectName:=$1
End case

If ($t_ObjectName#"")
$t_DataSource:=Object Get Expression ($t_ObjectName)

If ($t_DataSource#"")
EXECUTE FORMULA("__ObjectValue:="+$t_DataSource)
$0:=__ObjectValue  //Params and Locals can't be used in EXECUTE FORMULA
End if
End if


It's very round about code, but not particularly complicated, which makes
me wonder why 4D don't just give us some commands to do it.

Anyway, I hope these work for you.  They work for me.

-- 
Pete Hay
Managing Director
Foreground Software Limited
New Zealand
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to