realbasic-nug
[Top] [All Lists]

Re: The SuperClass already implemented the event???

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: The SuperClass already implemented the event???
From: Christian Dorn <realbasic@online.de>
Date: Fri, 27 Feb 2009 12:53:12 +0100
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <c32bad250902261632w1b70233cw8bc1ce56544b0396@mail.gmail.com>
References: <23974611.43218.1235655739076.JavaMail.www@wwinf2227> <c32bad250902261632w1b70233cw8bc1ce56544b0396@mail.gmail.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com

Am 27.02.2009 um 01:32 schrieb William Shank:

1) create Class1, a subclass of Canvas
create Class2, a subclass of Class1
in class2.mouseDown put: MsgBox "2"
now in class1.mouseDown put: MsgBox "1"

mouseDown in class2 is now italic. But you can use these classes, they
compile and msgbox the correct number.

That's _not_ how you should do this or you'll have strange problems later. And even if it compiles in current versions of Rb, it is likely to be broken in future releases. The correct way is to pass the event to the subclass. To keep your example, do the following:

1) In Class1 create a new MouseDown event (Project -> Add -> Event): MouseDown(x as Integer, y as Integer) as Boolean
2) Put the following code in the MouseDown event of Class1:

     Function MouseDown(x as Integer, y as Integer) As Boolean
          // This will pass the MouseDown event to Class2
          if RaiseEvent MouseDown(x,y) then
               // Class2 has handled the event
               return true
          end if

// You can add the code for the MouseDown event of Class1 here...
     End Function

3) Put whatever code you want in the MouseDown event of Class2, but make sure you return 'true' at the end. If you don't return 'true', the rest of the code in the MouseDown event of Class1 will also be executet.


ps. I find it weird that situation 1) does compile and overrides as expected.

This is definitely a bug.

Gruß
Christian

----------------------------------------
Christian Dorn
realbasic {a} online.de

REALbasic 2008.5-1 Pro
iMac 3.06 GHz Intel Core 2 Duo, 4 GB RAM
PowerMac G5 2x2GHz, 1.5 GB RAM
Mac OS X 10.5.6
----------------------------------------







_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>