This Question is Assumed Answered

1 "correct" answer available (5 pts) 13 "helpful" answers available (3 pts)
12 Replies Last post: Jul 6, 2008 9:42 PM by Poseidon.UD

How to pass the properties of the controller to the other controller?

Jun 29, 2008 11:23 PM

Click to view markecho's profile Level 2 markecho 35 posts since
Oct 17, 2007

Hi.

I have a problem about controller's property. "How to transfer the properties of the controller to the other controller?"

For instance.

I create an object that is the subclass of ControlFrame --- named AObject, then I assign many properties to AObject,

for example ,"height = 2cm", "width = 3cm", "enabled? = true","visible? = true" and so on...

later, I create a new object that is also the subclass of ControlFrame ---named BObject ,

now , I want to pass the properties of AObject to the BObject,

finally, BObject have the same properties with AObject's --- "height = 2cm", "width = 3cm", "enabled? = true","visible? = true"

what should I do?

Thank you for your advice.

Click to view URPradhan's profile Level 7 URPradhan 141 posts since
Mar 6, 2008
1. Re: How to pass the properties of the controller to the other controller? Jun 30, 2008 1:57 AM
Use clone-options method of Object1.
{let vb1:VBox = {VBox width = 3cm, height  = 3cm, background = {Background "red"}}}
{let vb2:VBox = {VBox}}
{vb1.clone-options vb2}|| clone-options takes the target object as parameter, to which the properties will be copied
{value
    let hb:HBox = {HBox
                      spacing = 10pt,
                      vb1,
                      vb2
                  }
    hb
}
Click to view markecho's profile Level 2 markecho 35 posts since
Oct 17, 2007
2. Re: How to pass the properties of the controller to the other controller? Jun 30, 2008 6:12 PM
in response to: URPradhan
thank you URPradhan,

but if I add many events to vb1, I want vb2 has the same events as vb1

for example :

{let vb1:VBox = {VBox width = 3cm, height = 3cm, background = {Background "red"}}}

{vb1.add-event-handler

{on PointerPress do

{popup-message "Hello"}

}

}

Then, when I click the vb2, it also pop up the "Hello" message. what should I do?

Thanks for your help.

Click to view carl's profile Curl carl 74 posts since
Oct 17, 2007
3. Re: How to pass the properties of the controller to the other controller? Jun 30, 2008 7:33 PM
in response to: markecho
EventTarget has:
protected event-handlers:#{Array-of EventHandler}

... but as it's protected you can't access it externally on existing Graphic classes.

I don't think I would recommend a bulk copy of event handlers anyway. There are cases where event handlers are added automatically, and in almost any such case you probably shouldn't copy it. For example, RecordSetDisplayNavigationPanel (often found in RecordGrid or RecordForm) adds a couple of event handlers to its associated RecordSetDisplay. If you copied those over to another RecordGrid, you would get a hidden performance drain, though fortunately, in this example, the behavior should stay correct.

Similar concerns apply to copying options. You can probably get away with that in many cases. But as an example, you wouldn't want to copy over the radio-frame nonlocal option if you were "cloning" a RadioFrame, or you would get unexpected behavior from the new RadioFrame's child RadioButtons.

If you're not dealing with Controls, then you'd be safer doing either of these copy operations, or possibly using Visual.clone-appearance. With Controls, you rather need to sort through the settings and decide which ones you really want to duplicate. If you are the one setting them, then it's probably better to remember which ones you want and set the list in bulk on your new Control.
Click to view Poseidon.UD's profile Level 2 Poseidon.UD 37 posts since
Jul 3, 2008
4. Re: How to pass the properties of the controller to the other controller? Jul 3, 2008 10:09 PM
in response to: URPradhan

textfield object, clone-options

TextField's properties of "Value" cann't clone.

*
{define-class public t2 {inherits TextField}

field ss:String = "d"*

  • {constructor public {default}*
  • {construct-super*
  • }*
  • set self.ss = "ddd"*

  • }

*
*}

*
{let vb1:TextField = {TextField width = 3cm, height = 3cm,

  • background = {Background "red"},*
  • value = "asdfasd"

}}*
{let vb2:TextField = {t2}}
{vb1.clone-options vb2}|| clone-options takes the target object as parameter, to which the properties will be copied
{value

  • let hb:HBox = {HBox*
  • spacing = 10pt,*
  • vb1,*
  • vb2*
  • }*
  • hb*
*}

*

Click to view carl's profile Curl carl 74 posts since
Oct 17, 2007
5. Re: How to pass the properties of the controller to the other controller? Jul 3, 2008 10:55 PM
in response to: Poseidon.UD
Right, clone-options will only clone actual options. Fields and accessors aren't included; value is a getter/setter. So is prompt, for example.
Click to view Poseidon.UD's profile Level 2 Poseidon.UD 37 posts since
Jul 3, 2008
6. Re: How to pass the properties of the controller to the other controller? Jul 3, 2008 10:41 PM
in response to: carl

"value is a getter/setter"

for example ,TextField's

1.bound-command
2.value-as-any
3.value
4.ui-object
5.valid? (readonly )

1,2,3,4,5 , cann't copy , is it right?
help.

Click to view carl's profile Curl carl 74 posts since
Oct 17, 2007
7. Re: How to pass the properties of the controller to the other controller? Jul 3, 2008 10:54 PM
in response to: Poseidon.UD
If you look up a property in the doc viewer and it doesn't say (local) or (nonlocal), it's not an option, so clone-options won't work for it.

That doesn't mean that you can't copy it yourself, just that there's no bulk method for it. Well, if it's a getter then you can't copy it anyway, of course. Some of those you shouldn't copy, even if you can. ui-object, for example, is not designed to be shared. .value would be fine to copy in this case.

Is there a particular use case that bulk-copy between Controls is being considered for? Generally that should not be necessary, given the alternatives of nonlocal options, LookAndFeel registrations, factory-type procs, etc.
Click to view URPradhan's profile Level 7 URPradhan 141 posts since
Mar 6, 2008
8. Re: How to pass the properties of the controller to the other controller? Jul 3, 2008 11:41 PM
May be Copy Constructor will solve ur problem too :)
Click to view Poseidon.UD's profile Level 2 Poseidon.UD 37 posts since
Jul 3, 2008
9. Re: How to pass the properties of the controller to the other controller? Jul 3, 2008 11:48 PM
in response to: URPradhan

ou? how to do
Click to view fukuta's profile BlackBelt fukuta 105 posts since
Oct 17, 2007
10. Re: How to pass the properties of the controller to the other controller? Jul 4, 2008 11:29 AM
in response to: Poseidon.UD
I'm not sure what the word 'Copy Constructor' means, but if you just wanted to copy .value from one control to another, why don't you do this??

set tf1.value = tf2.value


You're not looking for a way to copy all properties (fields, accessors and options), are you? As carl said above, there might be better alternatives. If you describe the details of what you really want to do, experts here must give you exact advice.
Click to view URPradhan's profile Level 7 URPradhan 141 posts since
Mar 6, 2008
11. Re: How to pass the properties of the controller to the other controller? Jul 6, 2008 9:30 PM
in response to: fukuta
fukuta wrote:I'm not sure what the word 'Copy Constructor' means, but if you just wanted to copy .value from one control to another, why don't you do this??

I'm not sure if Curl does supports it or not, the word Copy-Constructor means, creating new objects from existing objects (In C++ we call it Copy-Constructor).

If you have a live object of a class and you want to create another object of the same class with all the properties of the existing object then you have yo pass the existing object as a parameter to the constructor of the class. Bydefault compiler creates one CTor for you with a flexibilty to define your own custom CTor.
Click to view Poseidon.UD's profile Level 2 Poseidon.UD 37 posts since
Jul 3, 2008
12. Re: How to pass the properties of the controller to the other controller? Jul 6, 2008 9:42 PM
in response to: URPradhan

i see.thanks