Data Access Worldwide Knowledge Base

Article ID 2309
Article Title PROBLEM: Design-time Screen Sizes are not Applied when Running Application
Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2309
KBase Category VDF12
Date Created 05/09/2007
Last Edit Date 05/09/2007


Article Text
PROBLEM:
I am creating a VDF application and after adding more input fields to a view and testing the view I notice that the size of the view that I set in my source code is not respected. It looks like the previous size (from before changing) is used. How come?

SOLUTION:
The default for Visual DataFlex programs is to store in the registry the size and location of the main panel and views when exiting the program. The next time the program starts the size and location are restored and applied. This overrides the source based setting because the size and location are loaded in a later phase.

Storing and reloading the information is managed by the cApplication object property pbPreserveEnvironment. The default for "real" programs is TRUE and for test programs is FALSE. You can set the property for real programs during development time to FALSE but there is a (small) change that you could forget to make: set it to true before compiling your application for deployment. The following two options deal with that.

1. You can set the property to FALSE dynamically when a certain flag, like -X, is passed to the program.
End users will start the application by double-clicking the exe or via a shortcut and not pass the special parameter. Therefore, they will use the default setting.
You as developer can add the -X in the paramaters form in the project properties dialog of the Studio. In this case, the parameter will only be passed when the app is started from the Studio, i.e. at design time only. If you use the following code in your application you will set the pbPreserveEnvironment property to false when the -X is passed.

Object oApplication is a cApplication
    Set psCompany to "Data Access Worldwide"
    Set psProduct to "Visual DataFlex Examples"
    Set psVersion to "12.0"
    Set psProgram to "Order"
    Set psHelpFile to "Examples.chm"
    Set peHelpType to htHtmlHelp
    
    Procedure OnCreate
        Forward Send OnCreate
        
        Send CheckCmdLine
    End_Procedure
    
    Procedure CheckCmdLine
        Handle hoCommandLine
        String sFlag
        
        Get phoCommandLine To hoCommandLine
        Get Argument Of hoCommandLine 1 To sFlag
        If (Uppercase (sFlag) = "-X") Begin
            Set pbPreserveEnvironment To False
        End
    End_Procedure
End_Object    // oApplication

2. As an alternative of the above, you can also decide to remove the stored settings, resetting those properties to design-time values. You can even document this so that users have the option to reset the application settings to the default.
The following code checks (like above) for a special flag and blow away the key in which we store the information from the registry making the application run as if it was never started. If you do not want to remove the entire key, you can modify the code to do a partial erase.

Object oApplication is a cApplication
    Set psCompany to "Data Access Worldwide"
    Set psProduct to "Visual DataFlex Examples"
    Set psVersion to "12.0"
    Set psProgram to "Order"
    Set psHelpFile to "Examples.chm"
    Set peHelpType to htHtmlHelp
    
    Procedure OnCreate
        Forward Send OnCreate
        
        Send CheckCmdLine
    End_Procedure
    
    Procedure CheckCmdLine
        Handle hoCommandLine hoRegistry
        String sFlag sKeyName
        Boolean bKeyDeleted
        
        Get phoCommandLine To hoCommandLine
        Get Argument Of hoCommandLine 1 To sFlag
        If (Uppercase (sFlag) = "-RESET") Begin
            Get Create U_cRegistry To hoRegistry
            Get RegistryKeyString To sKeyName  
            Get DeleteKey Of hoRegistry sKeyName To bKeyDeleted
            Send Destroy Of hoRegistry
        End
    End_Procedure
End_Object    // oApplication


Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.