In the code below, clicking on the button ButtonChangeCursor changes the form's
cursor to a WaitCursor. Clicking the button ButtonRestoreCursor changes the
form's cursor back to its original cursor. For the reasons I explain below I
wouldn't expect this code to behave as it does, so why does it work?
Public Class Form1
Dim OldCursor As Cursor
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
OldCursor = Me.Cursor
End Sub
Private Sub ButtonChangeCursor_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButtonChangeCursor.Click
Me.Cursor = Cursors.WaitCursor
End Sub
Private Sub ButtonRestoreCursor_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButtonRestoreCursor.Click
Me.Cursor = OldCursor
End Sub
End Class
My confusion derives from the statement "OldCursor = Me.Cursor" in the Form's
Load event. After this statement executes, isn't the OldCursor variable
associated with the same object instance as the one that Me.Cursor is
associated with? That's what I would expect as the Dim statement for OldCursor
simply declares an object variable, it doesn't create a Cursor object. So if
OldCursor and Me.Cursor are associated with the same object, wouldn't any
changes to Me.Cursor affect OldCursor too? That's what I would expect, but
that's not what happens. 2 1545
Alex wrote: In the code below, clicking on the button ButtonChangeCursor changes
the form's cursor to a WaitCursor. Clicking the button ButtonRestoreCursor
changes the form's cursor back to its original cursor. For the reasons I explain
below I wouldn't expect this code to behave as it does, so why does it work?
Public Class Form1
Dim OldCursor As Cursor
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load OldCursor = Me.Cursor End Sub
Private Sub ButtonChangeCursor_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ButtonChangeCursor.Click Me.Cursor = Cursors.WaitCursor End Sub
Private Sub ButtonRestoreCursor_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ButtonRestoreCursor.Click Me.Cursor = OldCursor End Sub
End Class
My confusion derives from the statement "OldCursor = Me.Cursor" in
the Form's Load event. After this statement executes, isn't the OldCursor
variable associated with the same object instance as the one that Me.Cursor is associated with? That's what I would expect as the Dim statement for
OldCursor simply declares an object variable, it doesn't create a Cursor
object.
Right so far!
So if OldCursor and Me.Cursor are associated with the same object, wouldn't
any changes to Me.Cursor affect OldCursor too? That's what I would
expect, but that's not what happens.
You are correct that any changes to *the object that they are both
pointing to* would affect them both. However, saying
Me.Cursor =
isn't altering a cursor object; it's point Me.Cursor (which, like
OldCursor, is an object variable) at a different cursor object. If
Cursors were mutable objects (they might well be, I dunno), and you did
something like:
Me.Cursor.SomeCursorProperty = SomeNewValue
then yes, you would find that now OldCursor.SomeCursorProperty also =
SomeNewValue. But that is not what you are doing when you say Me.Cursor
= SomeOtherCursorObject.
This kind of thing was maybe easier to understand when Set was still
around? :)
--
Larry Lard
Replies to group please
Thank you Larry. Your explanation makes perfect sense. I'm glad I asked. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ssb |
last post by:
Hello,
This may be very elementary, but, need help because I am new to access
programming.
(1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor
?) the values one by one and...
|
by: waddley |
last post by:
I have a client who wants to have Access ask to save changes anytime
data is changed or added into the database. I'm not really an Access
guy, I actually run their servers, but have been dropped...
|
by: jobs |
last post by:
I'm trying to understand this and don't get it...
I found some code that looks like it's going to work if I can make
sense of how to position the div.
The code displays a div with some data...
|
by: Lee |
last post by:
Hi all, been playing with some code overriding WndProc to get
information about mouse events.
So far I've tried to capture when the left mouse button is pressed
using the code below.
Sometimes...
|
by: Patti |
last post by:
I am new to SQL and have created a stored procedure for a .net web
application. Unfortunately I had to use a cursor in the stored
procedure, so it is taking several minutes to execute because it...
|
by: shorti |
last post by:
db2 v 8.2 on AIX 5.3
I will try to explain as brief as I can what it is I need. I am
building a function that will be called multiple times where I will
need to return x amount of records each...
|
by: Greg Corradini |
last post by:
Hello,
I'm trying to perform a simple insert statement into a table called
Parcel_Test (see code below). Yet, I get an error message that I've never
seen before (see traceback below). I've tried...
|
by: AhmetYOL |
last post by:
Hi all;
How can i catch end of the cursor?
CREATE OR REPLACE FUNCTION "public"."fnc_rapthsbordro" (bastar date, bittar date, basmuk integer, bitmuk integer, basmak varchar, bitmak varchar,...
|
by: CK |
last post by:
Good Morning All,
Can use use a variable for the FOR clause in a cursor?
Example
I have
DECLARE @a varchar(50), @b varchar(50), @c varchar(50)
DECLARE @sql varchar(255)
DECLARE @x...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |