subForm, Form et object

Hi,
I try some tests to create new modern components.
For that, I want to use the object variable instance, the one you get with :
$ob_options:=OBJECT Get pointer(Object subform container)-> of Form

But, I get plenty of side effect for that.
First
I put the object type of the instance to “Object”.
Problem, in my subForm, Form = null. Then, I’m not able to do things like
Form:=$myObject (defined)
Form:=new object
Nothing works.
But Form.toto:=“toto” works too.

In the documentation, I’m supposed to get an object ! The only thing is I did not fill in “Variable or expression” as I want to access my instance with a pointer to the object (no process variable’s cost).

Second
Generally speaking, I discover that I’m not able to attribute Form to any other object from root, I can only manage properties in it. Is it true ? Why ?

Thanks for your answer.

Answering my self…

https://doc.4d.com/4Dv17/4D/17.4/Page-subforms.300-4880698.en.html

Extract :
The object can be created automatically or be the parent container variable, if explicitely named and typed as Object (see below).

So I need to name it explicitly ?!? What a strange behavior as I need to declare Process variable to do so…
Any return from 4D ?
Is it something I can ask as a feature request ?

Olivier,

Sur le formulaire principal ouvert par Dialog, on a un Form.
En general, je predeclare un objet avec quelques sous-objets que je mets en 2e parametre de Dialog, ce qui cree un Form avec ces memes sous-objets.

Lorsqu’il y a un sous-formulaire a afficher, j’affecte une partie du contenu du Form a la variable du sous-formulaire.
Comme ce sont des objets, toute action sur l’un se repercute dans l’autre et vice-versa.
Ce n’est pas complique.
Si une action dans le sous-formulaire necessite une action dans le formulaire principal, il faut appeler le conteneur. Je n’en ai pas eu besoin pour le moment.
En fait, le plus complique a mon avis est de bien structurer le contenu du Form pur s’y retrouver.

Je peux te montrer par TeamViewer, si tu le souhaites.

: Olivier GRIMBERT

So I need to name it explicitly ?!? What a strange behavior as I need
to declare Process variable to do so…
Olivier,
I may be wrong, but I interpret “name” in the extract you cite as the form object name in properties, not as the variable or expression item.

By nam, I meant a named variable, like a process variable “myObject”.
It seems to work only if you do so : giving a variable to the suForm instance.

If not, I get a null for “Form”.

Thanks Bernard, but that was not my question !
I do as you often.

My question is about the “Form” object, not working as I wish / expect…

Hello,

: Olivier GRIMBERT

My question is about the “Form” object, not working as I wish /
expect…
As explain in the https://doc.4d.com/4Dv18R2/4D/18-R2/Form.301-4803671.en.htmldocumentation>, Form is not an object, but a command that returns an object. So you can’t write Form:=new object because you try to assign a value to a command.

Oh, thanks for this precisions.
Now I understand my blunder.

So, without a declared variable, how can I get an object instance for my widgets ?
Usable with self inside instances, and Form inside them ?

from the top of my head
in host : OBJECT Get pointer(named object;“subFormName”)
in subform : OBJECT Get pointer(Object subform container)

Read carefully what I said :

post 1) I get a null for Form or OBJECT Get pointer(Object subform container).
post 2) The documentation lets suppose you must have a declared variable for the instance which is what I don’t want.

I tried obviously what you say ! :slight_smile:

: Olivier GRIMBERT

The documentation lets suppose you must have a declared variable for
the instance which is what I don’t want.
You need to declare a variable if you want to pass it as the parent container variable.
If you don’t pass an object to the parent container variable, an empty object is created automatically. So Form command returns this empty object. You can use it in your code like a normal object: Form.test=“Hello”

: Fabrice MAINGUENE

You need to declare a variable if you want to pass it as the parent
container variable.
If you don’t pass an object to the parent container variable, an
empty object is created automatically. So Form command returns this
empty object. You can use it in your code like a normal object:
Form.test=“Hello”

Hi Fabrice,
this is not what I get: rather than an empty object, I get a null object and I can’t do anything with it as with Form I’m not able to associate a new object.
This is my issue!

You can see that Form = Null
[]34570811;“on load of an instance”[/]

You can see I’m able to create New Object on the pointer, then Form too.
[]34570828;“After initialization by code”[/]

So I think I solved it, knowing that Form is a command.
I just need to create an object using :
<code 4D>
$ptr_ob_options:=OBJECT Get pointer(Object subform container)
$ptr_ob_options->:=New object

</code 4D>

So it works ! Thanks for your support, and I hope it will help :slight_smile:

Oh I have forgotten:

what I do inside the subForm for this object is the same referenced by self in the instance, what I wanted.
A “bridge” between inside and outside!

The command Form return a null value during the On Load event because the subform is loaded before the host form. So the associated object with the container doesn’t yet exists.

You must deport your code at your choice:

  1. Into an On Timer event by calling SET TIMER(-1) during On Load event
  2. Into the On Bound variable change event

Thank you for your answer Vincent.

: Olivier GRIMBERT

this is not what I get: rather than an empty object, I get a null
object and I can’t do anything with it as with Form I’m not able to
associate a new object.

The command Form returns a null value if you declare your expression type in your parent container as object and you don’t associate a variable.
Just change the expression type to another type (like Undefined for example) and Form command returns an empty object maintained by 4D in the subform context.

I need a bridge, Fabrice. So I need an object binded between parent container and in subForm context.
If I declare my expression type in my parent container as Undefined, I get a Undefined pointer, and an undefined Form.

Ok then, my workaround:
In on load event of my subForm
<code 4D>
$ptr_ob_options:=OBJECT Get pointer(Object subform container)
$ptr_ob_options->:=New object

</code 4D>

It works well and it seems 4D do not create after that a new object (as said by Vincent) when executing the parent container “on load”, as it founds already one existing. I guess that because this created object in the subForm context is then the one I see by using “self” in my parent container.

I also got a very strange issue with objects:

<code 4D>
// THIS DO NOT WORKS, WHY ?
// $ob_options is correctly set from $ob_options_init
// Form Object “ob_options” remains null
$ob_options:=OBJECT Get pointer(Object named;“ob_options”)->
$is_onLoad:=OB Is empty($ob_options)
If ($is_onLoad)
$ob_options:=OB Copy(<>ob_options_init)
End if

// THIS WORKS!
$ptr_ob_options:=OBJECT Get pointer(Object named;“ob_options”)
$is_onLoad:=OB Is empty($ptr_ob_options->)
If ($is_onLoad)
$ptr_ob_options->:=OB Copy(<>ob_options_init)
End if

</code 4D>

: Olivier GRIMBERT

$ob_options:=OBJECT Get pointer(Object named;“ob_options”)->

<code 4D>
$ob_options:=(OBJECT Get pointer(Object named;“ob_options”))->
</code 4D>

Why Bertrand ? This is not same behavior ?

Ok I understood:

When Object is not even existing, you can’t get it then if you affect OB Copy to it, the object is not related to the form, it is “orphan like”.

So I need to declare it with a pointer, then I can use the object directly once initialized, even to empty.

Ouf !