Results 1 to 7 of 7
  1. #1
    Join Date
    May 2004
    Posts
    3

    Question Unanswered: Prevent Open Form

    hi all,
    i need to prevent open of a paradox form from windows explorer. When users double click a form file it open in paradox runtime and bypass any application control. Thx for answer and sorry for bad english

  2. #2
    Join Date
    Oct 2003
    Posts
    107
    Place this code in the init method of each form you don't want them to open:

    Code:
    var
      openForms Array[] String
    endVar
    
    enumFormNames(openForms)
    ;openForms.view()
    
    if not openForms.contains("the TITLE of your main menu form goes here")
    	then  msgStop("Security Violation:","You cannot open this form without going through the Main Menu system")
       		eventinfo.setErrorCode(canNotArrive)
    			close()
             return
    endif
    This will prevent any form from opening unless the control form (like a main application form) is actually open. It's not perfect as they could technically open the main application form and then browse to one of the others, but it keeps casual power users from messing around.

    It's important that you put the TITLE value of the form, not the form name. I included the commented-out line openForms.view() as a debugging tool to use if the code doesn't see your main form as really being OPEN. This will list all open forms by TITLE so you can check to make sure you are referencing the right TITLE.

    Hope this helps
    Last edited by lmckelvy; 05-26-04 at 11:51.

  3. #3
    Join Date
    May 2004
    Posts
    3
    Thx for help but that don't resolve any issues of my problem because i need to stopping form opening from windows explorer even if my main form is open. This because main form could request some authentication before a form is opening. I need also resolve this problem with code in main form only if is possible. Thx for any other helps.

  4. #4
    Join Date
    Oct 2003
    Posts
    107
    Then the only other thing I can think of is to not allow the form to open unless an environment variable is properly set.

    For example, in your main form when a support form is called you set an environment variable to a value. When the support form opens, it should check the environment variable. If the variable value is right, the form should reset the variable to a bs value and open normally.

    Example:

    On the main Form, say from a pushButton event:

    Code:
    var
     myForm     Form
    endvar
    
    writeEnvironmentString("FormStat", "OkayToOpen")
    
    myForm.open(":myAlias:theform.fdl")
    In the init method of each form:

    Code:
    var
     secretCode    string
    endvar
    
    ;get current string value
    secretCode = readEnvironmentString("FormStat")
    
    ;reset environment variable
    writeEnvironmentString("FormStat", "DoNotOpen")
    
    if secretCode <> "OkayToOpen"
    	then  msgStop("Security Violation:","You cannot open this form without going through the Main Menu system")
       		eventinfo.setErrorCode(canNotArrive)
    			close()
             return
    endif

  5. #5
    Join Date
    May 2004
    Posts
    3
    That's good. I think same mode... only other questions. There is a method for intercept open of a form from main form and get handler of that form? In this case i've a possibility to write control code for opening in main form only... thank you very much for attention

  6. #6
    Join Date
    Oct 2003
    Posts
    107
    I don't know for certain as I've never tried anything like that. I would guess that you would need to check for open forms on a regular interval (maybe using a timer) and if any are opened, close them.

    You would probably need to grab an array of open forms and if the size is greater than 1 (meaning more than just the main form is open), then you would do a while/endwhile loop to step through each open form, attach to it by title and close it if it's not your main form.

  7. #7
    Join Date
    Aug 2003
    Location
    Bologna - Italy
    Posts
    209
    Don't try to close opened forms, that would always be error prone.

    You should PREVENT opening of forms with the trick that lmckelvy has told you, and then be sure they can't open at all, instead of trying to close them after they've been opened.

    Bye!
    The only failure is not trying to do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •