home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.paradox      To crash or not to crash, asks Borland      9,834 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 9,303 of 9,834   
   Robert Wiltshire to Rick Rans   
   Re: Preventing a form from opening a sec   
   27 Jul 08 03:37:35   
   
   From: nomail@nospam.com   
      
   Ok, solved good enough for me.   
      
   The pita issue on this ended up being that   
      
   >the issue to get pdox form handle is difficult   
   >because both instances have the same exact title.   
      
   Originall, my second solution from the first post,   
   was to change title after form was open,   
   so that when 2nd instance tried to open,   
   I had different titles to work with ,   
   and therefore could stay totally with pdox methods   
   of attach and bringToTop.   
      
      
   Using that approach,   
   plus reading suggestions leads me to   
   a slightly more efficient approach to that technique.   
   Instead of modifying the title after it opens,   
   I modify the form title of the second instance of the form,   
   which is about to be closed anyways.   
      
   The steps are like this   
      
   get handle of form opening for second time   
      fThis.attach()   
   gettitle for form   
      stTitle = fThis.getTitle()   
   get all form names into array   
       enumFormnames(arForms)   
   cycle through array and see how many times stTitle exists in arForms   
        used a for loop and test to see if arForms[x]=stTitle   
      
   if arForms contains stTitle 2 times, then change title of opening form   
       fThis.setTitle(stTitle+"2")   
   Since we will be closing this 2nd instance of the form,   
   it does not matter if we change the title.   
      
   That will leave us with only one form with stTitle as its title,   
   and it is simple matter to attach and then bringToTop.   
     fOrig.attach(stTitle)   
     fOrig.bringToTop()   
      
   Thank you all for taking time to read this and offer suggestions.   
   It was much appreciated and helped with the brainstorming process.   
      
   Robert Wiltshire   
      
      
      
   ****Final code below  ***************   
      
   Code in the init section now looks like this   
      
   method init(var eventInfo Event)   
      
   if isFormOpeningAlreadyOpen() then   
    eventInfo.setErrorCode(canNotArrive)   
    close()   
    return   
    endif   
      
   endMethod   
      
      
   and code in custom method looks like   
      
   method isFormOpeningAlreadyOpen() logical   
      
   var   
    fThis,fOrig form   
    stTitleThisForm string   
    arForms array[] string   
    liEach,liMatches longint   
   endvar   
      
    attach to current form, and get its title   
   fThis.attach()   
   stTitleThisForm = fThis.getTitle()   
      
   use opal enum method to populate array,   
    and then count number of times current title is in array   
   enumFormnames(arForms)   
   liMatches = 0   
   for liEach from 1 to arForms.size()   
    if arForms[liEach] = stTitleThisForm then   
     liMatches = liMatches + 1   
     endif   
   endfor   
      
   if found zero or one time, then not already open   
   if liMatches <= 1 then   
    return(false)   
     endif   
      
    since we will be closing this form   
    modify its title, so that attach gets other form   
   fThis.setTitle(stTitleThisForm+"2")   
      
   if fOrig.attach(stTitleThisForm)   
    then   fOrig.bringToTop()   
    else   msgStop("Error","Did not find 2nd instance of form")   
   endif   
      
   return(true)   
      
   endMethod   
      
      
      
      
      
      
      
      
      
      
      
      
      
      
   "Rick Rans"  wrote in message   
   news:488b8e75$1@pnews.thedbcommunity.com...   
   > Robert   
   >   
   > I think I would go with your first thought with the following additions.   
   >   
   > 1. If your form doesn't exist as an open form, then open it and give it a   
   > different name.   
   > 2. Next, since your open form has a different name, change the check of   
   > the enumerated list and for the new form name and if it exists, then the   
   > form is open.   
   > 3. Since the open form has a different name than the form you are trying   
   > to open, you can do a bring to top the form you want on top and close the   
   > form that is opening.   
   >   
   > Just a WAG, but hope it helps. - Rick   
   >   
   > "Robert Wiltshire"  wrote in message   
   > news:488aad74$1@pnews.thedbcommunity.com...   
   >>   
   >> I have a form that assists me with programming tasks,   
   >> and I would like to make sure it does not open a second time.   
   >>   
   >> Using a script,   
   >> I am familiar with doing something like the following   
   >> ( I am typing this off the top of head, so it is not syntax checked )   
   >>   
   >> stFormname=":ztools:\\coding\\pickfields.fsl"   
   >> stTitle = "Pick Field Utility"   
   >> if not f.attach(stTitleOfForm)  then   
   >>    f.open(stFormname)   
   >> endif   
   >>   
   >> And that would be fine,   
   >> except, as part of my issue,   
   >> I would like the code to be *inside* the form itself,   
   >> not in an external script.   
   >>   
   >> I ended up figuring out 2 ways to do this,   
   >> and I wanted to share this experience,   
   >> but I welcome any input from others on how to do this.   
   >> This post gets a little long,  so proceed with caution.  =)   
   >>   
   >> Remember, I want the prevention code to be inside the form,   
   >> not in an external script, form, or library.   
   >>   
   >>   
   >> Solution 1 :   
   >>   
   >> I decided to start in the init section of the form,   
   >> and I am using either pdox 10 sp3 or pdox X3.   
   >>   
   >> Inside the form, I found the following useful :   
   >>   
   >> f.attach()   
   >> stTitleThisForm = f.getTitle()   
   >>   
   >> This allows me to fetch the title on the fly, as the form that is   
   >> opening,   
   >> and eliminates the need to hard code the form title.   
   >> ( which I think is a huge plus )   
   >>   
   >> I then used enumFormnames(arForms) to list all open forms to an array,   
   >> and I can step through that array to see that the form is in there twice.   
   >> If I find that arForms contains stTitleThisForm more than once,   
   >> I simply exited the form that was loading as follows :   
   >>   
   >> eventInfo.setErrorCode(canNotArrive)   
   >> close()   
   >> return   
   >>   
   >> This closes the form, and only leaves one instance of the form open on   
   >> the desktop.   
   >> But, that form is not guaranteed to be on top,   
   >> and even though I did not want this form open 2 times,   
   >> I did want the open copy of this form to come to the top of the pile.   
   >>   
   >> So as many programming tasks happen,   
   >> the main idea was fairly easy, but the last touch was a pita.   
   >>   
   >>   
   >> If I had a form handle, I could use f.bringToTop(),   
   >> but.........I dont see any way to get a handle to the first instance of   
   >> the form,   
   >> from the code in that form as it is opening the second time.   
   >>   
   >> The problem is, the title of the 1st instance is the same title as the   
   >> 2nd instance,   
   >> and we are now talking about the code that is running in the 2nd instance   
   >> of the form.   
   >>   
   >> If you call enumFormnames(arForms)   
   >> and then call ( or somethign similar, depending on what forms open)   
   >> if arForms[1] = arForms[2] then   
   >>    msgInfo("Note","2 titles are the same")   
   >> endif   
   >> So, this proves that pdox thinks both instances of the form have the same   
   >> name.   
   >> Obviously the above indexes to the array need to be correct,   
   >> to reflect where they are ni the array.   
   >> I simply used arForms.view() to look at array and determine necessary   
   >> index.   
   >>   
   >> Trying   
   >> f.attach(arForms[1]) and f.attach(arForms[2])   
   >> always returned a form handle to the 2nd instance of the form,   
   >> which makes sense , since it was the same exact title.   
   >>   
   >> Without the form handle,   
   >> I was unable to call the pdox form method bringToTop.   
   >>   
   >>   
   >> I did find that there was a windows api call,   
   >> and the uses statement looks like   
   >>   
   >> "USER32"   
      
   [continued in next message]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca