Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Preview issues

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Globalizer Support
View previous topic :: View next topic  
Author Message
sheitman



Joined: 27 Apr 2010
Posts: 98

PostPosted: Tue Feb 22, 2011 1:55 pm    Post subject: Preview issues Reply with quote

Hi,

we have some serious problem with the preview.
Unfortunately our controls contains contains calls to query data from the database inside the constructor oder Load-Event/Load method where we get an exception in the designer.
To prevent this we added
Code:
if (LicenseManager.UsageMode != LicenseUsageMode.DesignTime) {
...
}

to seperate this calls.

When we use Globalizers Preview we get this exceptions again so I guess the if statement fails here.
Is there some way you could change it or what we could do?

Best regards.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Feb 22, 2011 11:27 pm    Post subject: Reply with quote

The Globalizer help has the following advice to ensure that forms and controls can be previewed:

Quote:
The default constructor (and OnLoad method) should not invoke code that depends on external initialization (since this may cause an exception when Globalizer.NET attempts to create the form/control without the initialization having occurred)

One simple coding technique to achieve the above conditions, for forms/controls that do need to access externally initialized data, is to provide a second constructor that takes the data object as a parameter. The form/control saves this in a member variable and each event handler that needs to access the data simply returns if the member variable is uninitialized (ie Null/Nothing).


In your case because you already have a substantial amount of code and some checks in place to avoid similar issues with the visual studio designer an alternative approach may be easier.

Simply add the following static class to your project:

Code:
public static class DesignUtilities
{
    private static _inDesignMode = true;

    public static bool InDesignMode
    {
        get { return _inDesignMode; }
        set { _inDesignMode = value; }
    }
}


In the main() method for your application, before creating any forms, you call:

Code:
DesignUtilities.InDesignMode = false;


Then you can replace your existing checks with:

Code:
if (!DesignUtilities.InDesignMode) {
...
}


This check will work with both Visual Studio designer and Globalizer previews.
_________________
Infralution Support


Last edited by Infralution on Wed Feb 23, 2011 9:04 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
sheitman



Joined: 27 Apr 2010
Posts: 98

PostPosted: Wed Feb 23, 2011 2:08 pm    Post subject: Reply with quote

Wow, thanks for the tip. I will give it a try.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Globalizer Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group