Simplistically Dim gives you an instance of an object, Initialize makes it ready to use. Not all things need an call to Initialize to make them usable, like variables and arrays, but other more complicated things do.
Sorry to activate an old thread, but I am still a bit confused on this issue. I tried searching for info related to vb about this, but wasn't able to find anything that really cleared it up for me. Part of the reason may be that I don't understand sender objects well enough to get much out of the code example. Can someone provide a more in depth explanation, or point me to a resource that can help me understand the differences and how to know when things should be initialized or not?
If an object has an Initialize method then you need to call it before you "use" any of its other methods.
Two exceptions:
- Views added with the designer are initialized when the layout is loaded.
- This is not really an exception, however if you assign one variable to another then they both reference the same object:
B4X:
Dim sql1, sql2 As SQL
sql1.Initialize(...)
sql2 = sql1
sql2.Initialize <-- wrong, object was already initialized
So Dim sets up a reference to an object/variable and tells the program to set aside a certain amount of memory that the object/variable value can be stored in. Like using the term 'shotgun' to claim the front passenger seat in a car before you are actually sitting there...
Initialize causes the actual object/variable data to actually be stored in the memory that has been set aside for it by the Dim statement. Like actually sitting in the car.
Does this sound right?
And if so, some things don't need to be initialized in code because the data for that reference is already actually stored/available in memory?
Thanks for helping me wrap my brain around this one Erel.