Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Class definition problem
Message
From
30/05/2001 03:51:33
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
29/05/2001 23:57:10
Jimi Lee
Pop Electronic Products Ltd.
Hong Kong, Hong Kong
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00512512
Message ID:
00512536
Views:
9
This message has been marked as the solution to the initial question of the thread.
Jimi,
You were very close :)
In not working sample 1, detector is not part of class. Added in init. In second where you used 'add detector...' it's part of class (subclassed)and 'detector.click' would work there :) In procedure declarations you never need to and can't use this.click. Just 'Click' means 'this.click'. Better to show in code :)
do form shapeclicker && Assuming you have an empty Shapeclicker form
for i=1 to 5  && to put 5 object on the form, named Room1 to Room5
  shapeclicker.addobject("Room"+alltrim(str(i)), "MyRoom")
  with eval("shapeclicker.Room"+alltrim(str(i))) && Cascade
  	.Left = (i-1) * 50
  	.Top = (i-1) * 50
  endwith
endfor
shapeclicker.Setall('Visible',.T.) && Make them visible
This is the same code for following different style class declarations :
1)
define class MyRoom as container
  add object "Detector" as MyShape

  procedure Detector.click && Parent IS Roomn - part of Room class
    wait window "Clicked "+this.parent.Name timeout 2
  endproc
enddefine

define class MyShape as shape
  Top=0
  Left=0
  procedure init
    with this
      .borderstyle=0
      .backstyle=0
      .Height=.Parent.Height && Size itself to parent's size
      .Width=.Parent.Width
    endwith
  endproc
enddefine
2)
define class MyRoom as container
  procedure Init
    this.addobject("Detector", "MyShape")
  endproc
enddefine

define class MyShape as shape
  Top=0
  Left=0
  procedure init
    with this
      .borderstyle=0
      .backstyle=0
      .Height=.Parent.Height && Size itself to parent's size
  	  .Width=.Parent.Width
    endwith
  endproc
  procedure Click && Parent MIGHT BE Roomn - not part of Room class
    wait window "You clicked "+this.parent.Name timeout 2 
    with this
      .Backstyle = 1
      .Backcolor = rgb(255,255,0)
    endwith
  endproc
enddefine
So what's the difference between 'this.addobject' and 'add object' ? Well in first you only 'add' it to room, in second 'subclass' in room :) You should see the difference with these code (just change the MyRoom definition in above 2nd):
define class MyRoom as container
  add object "Detector" as MyShape

  procedure Detector.click && Parent IS Roomn - part of Room class
    wait window "Now You clicked "+this.parent.Name ;
    	timeout 2
* UNCOMMENT following line and retest
*    dodefault() && Call parent CLASS click code 
  endproc
enddefine
PS: DoDefault() call might be anywhere in code (before or after wait window here) and as many times as you want depending on when you want it to execute (kinda include).
Cetin


>hi all,
>
>I'm gonna create an container object on a form and place a shape on it, where it can detect mouse click and do some stuff. The following code works fine:
>

>do form main
>for i=1 to 5 && to put 5 object on the form, named Room1 to Room5
> main.addobject("Room"+alltrim(str(i)), "MyRoom")
>endfor
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform