Android Question Must use DOEVENTS...

Rusty

Well-Known Member
Licensed User
Longtime User
I am using Reflection to measure a label text width.
If I don't put in a Doevents, (see below), the returned value is random or "previous" value from prior calls.
Is there a better (non-Doevents) way to get this to work consistently?
Thanks,
Rusty

The code is as below.

B4X:
'MAIN inline code, Label1 is loaded in a .bal layout
    Type CameraSize (Width As Int, Height As Int)
...
            Label1.Text = "yes"
            Label1.TextSize = 14
            DoEvents                                       '<---<<< without this, it returns either "random" or previous values
            Dim tmpSize As CameraSize = Fn.GetLBLTextInfo(Label1)
B4X:
'gets the text size of a label
'returns CameraSize (ENM) width and height type structure
Sub GetLBLTextInfo(lbl As Label) As CameraSize
    Dim tmpSize As CameraSize
    tmpSize.Initialize
    Dim TMS2 As Reflector
    lbl.Width = -2
    lbl.Height = -2
    TMS2.Target = lbl
    tmpSize.Width = TMS2.RunMethod("getWidth")
    tmpSize.Height = TMS2.RunMethod("getHeight")
    Return tmpSize
End Sub
 

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks for the suggestion, but Sleep(0) doesn't work.
In fact, without an error (I tried Try/Catch) it exits my routine immediately and does not continue past that line.
(In my code snippet in post #1 the Doevents is changed to Sleep(0) and no line below the Doevents ever fires...)
Regards,
Rusty
 
Upvote 0
Top