Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Application object
Message
From
06/10/2005 08:31:41
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01056217
Message ID:
01056688
Views:
16
>Hello Cetin, thanks for your reply, see my reply to Bonny for a better explanation of my problem, thanks again

OK I read it and still the thread I referred to applies.
Data and the UI (form) itself are 2 distinct things. Thing the form as a glove and data as the hand. Data doesn't need to be a member of the form.
When you design a form with VS generally it guides you to create:
-A dataadapter (private OleDbDataAdapter da)
-A connection (private OleDbConnection con)
-A dataset ( private DataSet myDataSet )

and you bind controlsources like:

myDataGrid.DataSource = myDataSet;

and call:
da.Fill(myDataSet)

Those objects are private members of the form as designer guides you to create and instead could be written as:

this.myDataGrid.DataSource = this.myDataSet;

this.da.Fill(this.myDataSet)

Note that they don't have to be members of the form. It might be instead:

this.myDataGrid.DataSource = myAppClass.CommonDataSet;

Trying to make an anology with VFP:

"You have such a form. Data is collected through various sources in load event. Form objects have controlsources pointing to final Alias.FieldName or Alias (ie: a grid). Since it takes a lot of time to collect that data you want the form to load once and then show/hide. However form doesn't need to do that collecting in its own load method.
A separate routine could do that at application startup and keep data ready (might be a database and table(s) or just cursor(s). The form load method then is uncessary for collection, all it does to make sure the 'collected' is in use. You can then simply:
do form myForm && and release when done
...
do form myForm && and release when done

since data is always ready it's only binding that takes time (and that's almost zero seconds)."

Now in .Net if you collect the data you need

In the thread I referred read how to create a custom 'application'. With a class like that you could have application wide constants,static or nonstatic methods etc. So you create your application class and collect data to a dataset which is a member of your application class.
namespace myApplication
{
 class definitions
 {
  public static readonly DataLocation myDataLoc = new DataLocation();
 }
 class DataLocation
 {
   // fields    
   private DataLocation() {...}
 }

 class CommonData
 {
   private static DataSet ds;
   public static DataSet SharedDataSet { get {return ds;} } 
   static CommonData() { // collect your data and put in ds }
 }
}
You could now instead use the dataset from that. You wouldn't initialize it separately. It's static and constructor would automnatically populate data on first reference. ie:

myDataGrid.DataSource = myApplication.CommonData.SharedDataSet;

To show the idea better here is a small code that shows how static would work for you:
using System;
namespace myApplication
{
  public class staticTest
  {
    private static int x;
    static staticTest()
    {
      x=25;
      Console.WriteLine("Constructor method. Member x is now:{0}",x);
    }
    public static int X { get {return x;} }
  }
}

namespace myTest
{
 class Test
 {
   static void Main()
   {
     for (int i=0;i<5;i++)
      { Console.WriteLine("Call number#{0}: {1} ",i,myApplication.staticTest.X); }
   }
 }
}
Note that only first call causes constructor code to run. Subsequent calls simply get initialized x.
Same way you would be populating your dataset once at first call to your form (assuming only that form initializes that data - else it might be initialized from anywhere in app). Looks like:
Application.Run(myForm);
//...
//Form gets to the point where it needs the dataset
// and your static constructor populates data 
// (if this is the first access in application to 
//          "myApplication.CommonData.SharedDataSet")
myDataGrid.DataSource = myApplication.CommonData.SharedDataSet;
// Somewhere later in code or when this form loads again

// Constructor of static method is already populated the dataset
// This simply gets the dataset
myDataGrid.DataSource = myApplication.CommonData.SharedDataSet;
IOW from the first attempt to access to dataset, it's there whenever wherever you need it application wide.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform