473,748 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help understanding the Cursor

In the code below, clicking on the button ButtonChangeCur sor changes the form's
cursor to a WaitCursor. Clicking the button ButtonRestoreCu rsor 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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
OldCursor = Me.Cursor
End Sub

Private Sub ButtonChangeCur sor_Click(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles ButtonChangeCur sor.Click
Me.Cursor = Cursors.WaitCur sor
End Sub

Private Sub ButtonRestoreCu rsor_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles ButtonRestoreCu rsor.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.


Nov 21 '05 #1
2 1554

Alex wrote:
In the code below, clicking on the button ButtonChangeCur sor changes the form's cursor to a WaitCursor. Clicking the button ButtonRestoreCu rsor 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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
OldCursor = Me.Cursor
End Sub

Private Sub ButtonChangeCur sor_Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ButtonChangeCur sor.Click
Me.Cursor = Cursors.WaitCur sor
End Sub

Private Sub ButtonRestoreCu rsor_Click(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles ButtonRestoreCu rsor.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.SomeC ursorProperty = SomeNewValue

then yes, you would find that now OldCursor.SomeC ursorProperty also =
SomeNewValue. But that is not what you are doing when you say Me.Cursor
= SomeOtherCursor Object.

This kind of thing was maybe easier to understand when Set was still
around? :)
--
Larry Lard
Replies to group please

Nov 21 '05 #2
Thank you Larry. Your explanation makes perfect sense. I'm glad I asked.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3162
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 populate a combo box with these names. (this way, I can display all the EMPLOYEE_NAME values) (2) In general, can I do additional processing on column values from
1
1918
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 into the roll because I have some understanding of it. Any help would be greatly appreciated, they have me on a serious time line and I've been pulling my hair out all day over this. Thanks in advance. -Walter
1
11970
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 when I mouse over an element (A column in an ASP.NET Gridview, but I suppose that's not important) Everything works great, except I can't seem to position the div where I want given scrolling.
1
4203
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 the clicks will register fine, and other times it'll cause an acess violation (Attempted to read or write protected memory. This is often an indication that other memory is corrupt.) So I'm wondering why this occurs and how I can prevent it from...
8
2104
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 has to read through about 15,000 records. There must be another way to do what I'm trying to do without a cursor. I've tried temp tables and case statements, but I can't seem to get them to work. I've been trying to figure this out for over a...
3
1933
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 time for the same basic query. I will be basically get passed in where I had left off the last call but it is two fields that make up this unique index. The main rule is that I cannot hold open a cursor on the record I last read because it...
3
1592
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 to put a semicolon at the end of the sql statement, but with no luck. Any ideas from more experienced mx.ODBC users? CODE TRACEBACK
1
2273
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, siralama varchar, tip boolean) RETURNS varchar AS $body$ declare intgelirkod integer; declare intgelirkod1 integer; declare gelircurs cursor for select gelirkod_idno from tbl_gelirkodlari order by gelirkod_idno; begin
4
1620
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 varchar(50), @y varchar(50), @z varchar(50) DELCARE outer_cursor CURSOR FOR
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.