New topic: 

getting a handle for a subclassed window

<http://forums.realsoftware.com/viewtopic.php?t=45567>

         Page 1 of 1
   [ 9 posts ]                 Previous topic | Next topic          Author  
Message        Rocky Scofield          Post subject: getting a handle for a 
subclassed windowPosted: Tue Oct 09, 2012 5:20 pm                         
Joined: Tue Nov 01, 2005 9:58 am
Posts: 128                Hello, all. I use a subclass of a Window for doing 
automated db linking. I have controls on this window (obviously). In the events 
of the controls, I would like to reference the subclassed window as property of 
the control, but the Window or TrueWindow property only can be placed in a 
variable dimmed as a Window, not as my subclassed window. Of course its window 
is my subclassed window and I have methods in that subclassed window that I 
want to use from within these controls that I can't get to them.

Short of creating a property that I can assign this subclassed window to, is 
there a way to do this?

I need to also mention that the events are also in subclassed controls, meaning 
the methods in the subclassed window are not accessible to them except as a 
runtime reference to the window, because a subclassed control's event is not 
aware of its window yet. I hope that make sense.

Thanks,

Rocky   
                             Top                charonn0          Post subject: 
Re: getting a handle for a subclassed windowPosted: Tue Oct 09, 2012 5:33 pm    
                             
Joined: Mon Apr 02, 2007 2:08 am
Posts: 916
Location: San Francisco, CA, USA                I think you want the Self 
keyword; for any code contained on a window or web page, Self refers to the 
window or web page.      
_________________
Boredom Software  
                             Top                Rocky Scofield          Post 
subject: Re: getting a handle for a subclassed windowPosted: Tue Oct 09, 2012 
6:08 pm                         
Joined: Tue Nov 01, 2005 9:58 am
Posts: 128                Thanks for your reply, charonn0. It seems that when 
you have a subclassed control and have code in an event (not an event 
definition that is coded off of the window), then self can only refer to the 
control itself, because it has no relationship with its window yet. So, in this 
case self is the same as me.

Rocky   
                             Top                timhare          Post subject: 
Re: getting a handle for a subclassed windowPosted: Tue Oct 09, 2012 6:52 pm    
                     
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11718
Location: Portland, OR  USA                You must test and cast the Window 
property.
if me.Window ISA myWindowSubclass then
  myWindowSubclass(me.Window).DoSomethingSpiffy
end

The test can be omitted if you are 100% sure that you will only ever use this 
control in your window subclass.  (Something that is never the case in reality, 
so always do the test.)   
                             Top                rjaber          Post subject: 
Re: getting a handle for a subclassed windowPosted: Tue Oct 09, 2012 8:48 pm    
                     
Joined: Mon Nov 22, 2010 4:51 pm
Posts: 50
Location: Stockholm, Sweden.                is it possible to reference from a 
class thats not subclassed?      
_________________
Richard B.
Real Studio 2012> OS X  
                             Top                timhare          Post subject: 
Re: getting a handle for a subclassed windowPosted: Tue Oct 09, 2012 9:04 pm    
                     
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11718
Location: Portland, OR  USA                What do you mean by "reference"?  
You can't edit a class that isn't a subclass, so I presume you mean from code 
in the class' events in the window?  There you would just use the properties 
and methods directly, since they are also part of the window.  You don't need 
to go through the gyrations of casting me.Window.   
                             Top                Rocky Scofield          Post 
subject: Re: getting a handle for a subclassed windowPosted: Tue Oct 09, 2012 
10:05 pm                         
Joined: Tue Nov 01, 2005 9:58 am
Posts: 128                Thanks, timshare for your solution, which worked. I 
have looped through and cast the controls of a window many times, but never 
thought of casting a window.

On your other question, a typical reason to subclass a control is to prebuild 
in functionality to make it reusable. I, for example, have subclassed a 
Textfield to automatically connect to a database. Part of this reusable 
functionality is to write some code in some of the events.

I do not want have to type the same code that I need over and over again in the 
event after the subclassed textfield has been placed on a window. So, I put the 
code in the event of the subclassed textfield and it is available without 
having to rewrite the code. The drawback is that it is more difficult to 
reference certain things...like the window.

Thanks again,

Rocky   
                             Top                timhare          Post subject: 
Re: getting a handle for a subclassed windowPosted: Tue Oct 09, 2012 11:55 pm   
                      
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11718
Location: Portland, OR  USA                Rocky Scofield wrote:On your other 
question, a typical reason to subclass a control is to prebuild in 
functionality to make it reusable. I, for example, have subclassed a Textfield 
to automatically connect to a database. Part of this reusable functionality is 
to write some code in some of the events.

Yeah, I got that.  What I didn't get was
Quote:is it possible to reference from a class thats not subclassed?
If it's not subclassed, why would you need to do anything special?   
                             Top                rjaber          Post subject: 
Re: getting a handle for a subclassed windowPosted: Wed Oct 10, 2012 5:43 am    
                     
Joined: Mon Nov 22, 2010 4:51 pm
Posts: 50
Location: Stockholm, Sweden.                timhare wrote:I presume you mean 
from code in the class' events in the window?  There you would just use the 
properties and methods directly, since they are also part of the window.  You 
don't need to go through the gyrations of casting me.Window.

SubWindow (super window)
 Property: bool as boolean

SubCanvas: (super canvas)
 if window isa subwindow
 if subwindow(window).bool=true then
 //so far so good

SubCanvasItem:
method: DrawInsideSubCanvas(g as graphics)
//how to get parent window.handle here?

Currently I use a global property in a module.      
_________________
Richard B.
Real Studio 2012> OS X  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 9 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to