with ... endwith structure

Discuss all feature requests you have for a new Servoy versions here. Make sure to be clear about what you want, provide an example and indicate how important the feature is for you

with ... endwith structure

Postby Boudewijn » Sun Feb 13, 2011 11:39 am

While referencing object on forms or the form itself it would be nice to see a possibility like

with thisform
{
.property1.value = somevalue
.property2.value = someOtherValue
.objectOnTheForm.property1.value = YetAnotherValue
.objectOnTheForm.Method_or_Event([parameters])
.Method_or_event([parameters])

with .objectOnTheForm // a "with structure" nested in the with structure
{
.property1.value = "xyz"
.property2.value = 123
.property3.value = globals.someFunctionReturningAValue()
}
}

this way one could be saved from typing the reference to the form/object on each and every line. Thus a real time saver.
When I could add a reference to the base object (form or whatever) that would be really great, as in

with thisform as SomeBaseForm in LibraryName
{
.customProperty1.value = somevalue
}
Boudewijn
 
Posts: 41
Joined: Sun Sep 26, 2010 8:35 am

Re: with ... endwith structure

Postby ROCLASI » Sun Feb 13, 2011 12:13 pm

Hi Boudewijn,

You can put objects into variables and use them as those objects like so:
Code: Select all
var f = forms.thisform; // form object
f.property1.value = somevalue
f.property2.value = someOtherValue
f.objectOnTheForm.property1.value = YetAnotherValue
f.objectOnTheForm.Method_or_Event([parameters])
f.Method_or_event([parameters])

var e = f.elements.objectOnTheForm; // element object
e.property1.value = "xyz"
e.property2.value = 123
e.property3.value = globals.someFunctionReturningAValue()


Hope this helps.
Robert Ivens
ROCLASI Software Solutions / JBS Group, Partner
SAN Developer / Servoy Valued Professional / Servoy Certified Developer
Twitter: @roclasi / @servoyforge
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5319
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: with ... endwith structure

Postby Peter de Groot » Sun Feb 13, 2011 12:18 pm

You could try,

with(forms.main){
elements.lbl_text.text = 'test';
}
Peter de Groot
 
Posts: 215
Joined: Thu Jan 10, 2008 8:38 pm
Location: Not sure...

Re: with ... endwith structure

Postby Boudewijn » Sun Feb 13, 2011 11:40 pm

to roclasi,

an object is just that, an object and not a variable. so if I add an object to a form then I want to be able to access that object and not the variable.
I know, I belong to the spoiled bunch of developers who are called "VFP developers", the crowd that is used to OOP in its purest form.
Since Servoy (the company) wants the VFP devvies to join the Servoy crowd I speak out what I am used to. and what I would like to see in Servoy as well.
No compromis.

BL
Boudewijn
 
Posts: 41
Joined: Sun Sep 26, 2010 8:35 am

Re: with ... endwith structure

Postby ROCLASI » Sun Feb 13, 2011 11:59 pm

Well excuse me Your Highness.
With such an attitude (in this and other posts) I wish you good luck with getting help.

I am out. No compromis.
Robert Ivens
ROCLASI Software Solutions / JBS Group, Partner
SAN Developer / Servoy Valued Professional / Servoy Certified Developer
Twitter: @roclasi / @servoyforge
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5319
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: with ... endwith structure

Postby Boudewijn » Mon Feb 14, 2011 12:04 am

roclasi,

I am asking questions. Addressing me as "highness" is a red light.
Totally confused about the complexity of the object model and indeed I have quite an outspoken opinion how things should work.
If you don't have the answers... just say so.

BL
Boudewijn
 
Posts: 41
Joined: Sun Sep 26, 2010 8:35 am

Re: with ... endwith structure

Postby Harjo » Mon Feb 14, 2011 12:49 am

Boudewijn,

you dont have to be that rude!
You are not talking to some kind of rookie here....
(yes I have read your other post's also, and I understand his reaction.)
Robert is trying to help you out here, and is NOT an employee of Servoy, or responsible of how Servoy works, whatsoever.

He even received a community spirit award last week, on the ServoyWorld conference in Amsterdam, for his contribution to the forum!
So, be nice, please!
Harjo Kompagnie
Direct ICT / Servoy Hosting / ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
User avatar
Harjo
 
Posts: 4296
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: with ... endwith structure

Postby pbakker » Mon Feb 14, 2011 11:29 am

Boudewijn,

The code structure you ask for is already possible at Peter showed:
with(forms.main){
elements.lbl_text.text = 'test';
}


However, while you might be used to this, it's considered bad practice to use in in the JavaScript world. Such bad practice even that in future JavaScript specification the "with" statement is even deprecated.

So, better not use it.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: with ... endwith structure

Postby wiseguy » Mon Feb 14, 2011 7:12 pm

Here's a nice little article about this ... http://www.yuiblog.com/blog/2006/04/11/ ... d-harmful/.
Hugh Summerhays
Mainstream Data
wiseguy
 
Posts: 9
Joined: Thu May 15, 2008 6:46 pm
Location: SLC, UT, USA

Re: with ... endwith structure

Postby jgarfield » Mon Feb 14, 2011 9:04 pm

Boudewijn wrote:While referencing object on forms or the form itself it would be nice ...[stuff]....
this way one could be saved from typing the reference to the form/object on each and every line. Thus a real time saver.


In case this is what you are looking for, this hasn't been made clear yet.

If you are working in a function on form MyForm you do not have to use this syntax

Code: Select all
forms.MyForm.formVar1 = 'x';
forms.MyForm.formVar2 = 123;
forms.MyForm.foundset.fieldX = 42.13
forms.MyForm.elements.lblInfo = 'Verbosity";


you can just do

Code: Select all
formVar1 = 'x';
formVar2 = 123;
foundset.fieldX = 42.13
elements.lblInfo = 'Verbosity";


Technically in that example you don't even need the reference to foundset, but we find it's good practice to reference it that way so that it's clear that is where the action is happening.

As far as using with(blah) {} vs assigning what you are working with to a local variable, as far as javascript is concerned there's not much if a difference.

Code: Select all
var a = elements.lblInfo


All this does is create a reference to elements.lblInfo, it points to the same memory and everything...it's semantically the same...in fact, elements.lblInfo is itself just another variable in javascript that is a reference to a Java object in the underlying framework.

The difference that you get with using with(blah) {} is (if I recall my finer points of javascript correctly) that it creates another node on the scope chain, changing what the this keyword is looking at. However, like Paul said, this is a language feature that is scheduled to be deprecated in a future version of JavaScript, so unless you want to have to change your code when the Servoy JavaScript engine gets updated, it might not be a great idea to use it.

If you are really looking for that kind of block scoping JavaScript does provide another pattern you can use which looks something like this
Code: Select all
(function (o)
{
     o.property1.value = 1
     o.property2.value = 'x'
     o.method()
})(objectToWorkWith);


Where you create a one off anonymous function and pass your object in to do all the work on. You get your localized block scope, your shortened typing times, but you still have to reference your object with o.

As you can see, there are several ways to accomplishing the same concept that you are talking about, however whenever you switch languages you should expect to have to endure a few syntactical and paradigm changes.
Programmer.
adBlocks
http://www.adblocks.com
jgarfield
 
Posts: 223
Joined: Wed Sep 28, 2005 9:02 pm
Location: Boston, US


Return to Discuss Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest