Popup Window: Preventing pile-ups

By Dennis Brown

The popup window is a great tool in debugging and can help you to keep track of what your code is doing or it can be used to alert you to special situations in your normally running formula. A common problem is that if you call PopupWindow() from a loop or if one gets generated on every AFL pass, you can get hundreds or even thousands of pop-ups piling up on your screen. Tomasz posted a simple work-around on the AmiBroker Feedback Center that took care of the problem in some cases (Suggestion 1528):

The following is a more complete version of this solution that adds a popupID to keep track of each individual popup window and re-enable the popup after its specified timeout period, or if any of the displayed text changes:

function GetSecondNum()
    Time Now);
    Seconds intTime 100 );
    Minutes intTime 100 100 );
    Hours intTime 10000 100 );
    SecondNum intHours 60 60 Minutes 60 Seconds );
    return SecondNum;

function PopupWindowExpopupIDbodytextcaptiontexttimeoutlefttop )
    displayText bodytext captiontext;
    if ( ( StaticVarGetText"prevPopup" popupID ) != displayText) OR ( StaticVarGet"prevPopupTime" popupID ) < GetSecondNum() ) )
        StaticVarSetText"prevPopup" popupIDdisplayText);
        StaticVarSet"prevPopupTime" popupIDGetSecondNum() + timeout );
        PopupWindowbodytextCaptiontext popupIDtimeoutLefttop );

PopupWindowEx"ID:1""testing""test alert "5, -1, -);
PopupWindowEx"ID:2""testing""test alert "50);
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.25 out of 5)

Comments are closed.