Issue with Create() control on window under active window

I have code where I am adding controls onto a window structure.

The code below should as I read give the next control number

Controlno. =create(0,create:box)

However most of the time it returns correct control numbers, but sometimes it uses control numbers that already exist.

This causes issues as I also destroy controls and were ending up with the wrong ones deleted.

Any suggestions as to why I am seeing this ?

I have sussed this out there is another warning window open during the embed call and the control numbers are coming from this window.

Might want to check your target

Hi yes I was thinking this. Took me 3 days to find this bug in my code. If I want to ensure the code creating controls is working on the main window, rather than the warning process window, how would I use target please ?

Save a &Window Reference before you open the Warning Window then SetTarget( SavedRef ) before your Create.

SaveRefWindow &WINDOW

    SaveRefWindow &= Window   !Save Ref to Original Window 
    open(WarnWindow) 
        SetTarget(SaveRefWindow) 
        Controlno = CREATE(0,Create:Box)      !Creates on Window not WarnWindow
        ... set PROPs on Box and UnHide ...
        SetTarget() 
    close(WarnWindow)

If in the Warning procedure the Window label of the open window may not be in scope. You can get a reference to the active window with System{PROP:Target}. You must do that before you Open(WarningWindow) and it becomes active.

SaveRefWindow &= System{PROP:Target}

1 Like

we had problems until we sent a message to the window procedure. This seemed to fix problems allowing a local create. Also maintaining a list of control numbers in queue allowed for fine control over control numbers.