← servoy magazine

[tip] the magic of -1

  • Tips

by Marcel Trapman
www.it2be.com

Again, talking to a fellow developer. We were discussing the use of 'refreshRecordFromDatabase(foundset, recordindex)'. Hmm, he said, that's a nice function but I can not use it because I want to touch the complete foundset and not just one record.
After going back and forth for a while I suddenly remembered the magic of '-1'. In some cases it sets default values in other cases it means 'all'. In this case, when setting the recordindex to -1 it solved the issue because it means 'all'...
Another example is calling a form in dialog. By setting the x,y,w,h coordinates to '-1' one sets the dialog at the default position and the width and height are based on the form width and height.

Cool huh...

Hope you will remember this one when you need it :)

Marcel

Comments (2)

Patrick Ruhsert
If I might add: getDatasetByQuery also takes a -1 as last parameter if you simply want all records that meet the query.
Marcel Trapman
Great addition Patrick, and there are a lot more of those floating around...