Help: Id's can be completly unreliable

zryip theSlug zryip.theslug at gmail.com
Wed Nov 10 21:26:36 EST 2010


On Wed, Nov 10, 2010 at 2:15 PM, Claudi Cornaz <claudi.c at fiberworld.nl> wrote:
> Hallo all,
>
> I have a big, and as yet, unsolvable  problem.
> I use quite some tmplt's (groups) I keep in a seperate stack and when I need
> one
> I copy this tmplt to the card or group where I need it. So far all works as
> expected.
>
> Now comes the problem: Very often one or more controls of this copyed tmplt
> or the copyed tmplt itself will get an ID of 0.
> This is more than a nuisance as I keep discovering more and more problems
> with controls with an ID of 0.
> The first problem is the long id the IDE/engine places  in the it variable.
> If there is a ID of 0 in it, it will be invalid.
> Which means if you do the following it will throw a error saying the control
> doesn't exist.
>
> on mouseUp
>   copy grp "myTmplt" of cd 1 of this stack to grp "myGrp" of cd 2 of this
> stack
>   set the name of it to "test"     -- it: group id 0 of group id 1012 of cd
> id 1002 of stack "myStack"
> end mouseUp
>
> I had to change a lot of code because of this. I couldn't be sure the long
> id in the it var was reliable,
> because it might contain a ID of 0.
> This problem can be solved as follows:
>
> on MouseUp
>   put the number of controls of grp "myGrp" of cd 2 of this stack + 1 into
> tCount
>   copy grp "myTmplt" of cd 1 of this stack to grp "myGrp" of cd 2 of this
> stack
>   set the name of control tCount of grp "myGrp" of cd 2 of this stack to
> "test"
> end mouseUp
>
> Now it doesn't matter if I copy a image/field or a group consisting of many
> controls,
> since tCount will point to the next layer within the destination, which will
> be the group in case a group get's copyed.
> (you can't use the last control of grp "myGrp" it will throw a error on
> compiling and anyway if you copy a grp
> the last control will point to the control with the highest layer within the
> copyed grp)
>
> Further if you use tmplt's which you copy, always and I mean always, use
> long names
> to point to a specific control, as you just can't trust the ID or the long
> ID. (a major rewrite of my code)
>
> Ok this is a nuisance, but there is at least a solution/workaround to it.
>
> Now I discovered a new problem with a control which has gotten the ill fated
> ID of 0.
> If it happens to be a field you can't get it's formattedWith/Height etc.
> I simply can't find a way to get at this, it always returns 0
>
> put the width of fld myLongNameFieldReference gives: 220
> put the value of yLongNameFieldReference gives: This is some text
> put the formattedWidth of fld myLongNameFieldReference gives: 0
>
> So the field exists (with a ID of 0) and it has text in it. But I just can't
> get the formattedWidth of it .
>
> I found in a rev lib stack a comment that the engine sometimes returns 0 as
> ID for controls and that they leave it at the moment.
> The problem is I now have a card with sometimes 10 or more controls with a
> ID of 0 which gives all kinds of problems.
>
> Does anyone know a trick or workaround to get the formattedWidth of my
> field?  Please.
> This is a complete stopper for me at the moment since I can't format my
> field and I use dozens of them which need to be
> formatted depending on there content.
>
>
> Hoping someone of you bright minds knows/finds something clever to solve my
> problem.
>
> Best wishes,
>   Claudi

Claudi,

Really odd.

The last ID is store in the stack and is incremented for each control
you add. For unicity you should not have two controls with the same
ID. That's why you can't set the ID of a stack to a lower number than
the actual ID. And the ID should be started at least to 1, probably
more for reserved usages, not 0

Could you precise:
- your system version
- your version of Livecode
- have you experienced this on several computers, always with the same
stack or with several stacks?


Regards,
-- 
-Zryip TheSlug- wish you the best! 8)
http://www.aslugontheroad.co.cc



More information about the use-livecode mailing list