Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Class definition problem
Message
From
30/05/2001 05:57:22
 
 
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:
00512560
Views:
8
This message has been marked as a message which has helped to the initial question of the thread.
Hi!

In the first approach, Detector is not known inside of the class definition, because it is added in run-time. Following works very well:
define class MyRoom as container
  add object "Detector" as MyShape

  procedure Detector.click
    wait window "You clicked me!"
  endproc
enddefine
or
define class MyRoom as container
  Detector = createobject("MyShape")

  procedure Detector.click
    wait window "You clicked me!"
  endproc
enddefine
It is called 'Late binding' and it is possible for VFP objects only.

For second case, just remove 'THIS' before Click.

HTH.

>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
>
>define class MyRoom as container
>  add object "Detector" as MyShape
>
>  procedure Detector.click
>    wait window "You clicked me!"
>  endproc
>enddefine
>
>define class MyShape as shape
>  procedure init
>    with this
>      .borderstyle=0
>      .backstyle=0
>    endwith
>  endproc
>enddefine
>
>
>But I want to pass parameter to the MyShape object such that I can do different motion when user click on different MyRoom object.
>
>So I changed the MyRoom class as following, but it says "unknown member DEDECTOR" at the line "procedure Detector.click"
>
>define class MyRoom as container
>  procedure Init
>    this.addobject("Detector", "MyShape")
>  endproc
>
>  procedure Detector.click
>    wait window "You clicked me!"
>  endproc
>enddefine
>
>define class MyShape as shape
>  procedure init
>    with this
>      .borderstyle=0
>      .backstyle=0
>    endwith
>  endproc
>enddefine
>
>
>I also tried this code but it says "unknown member THIS"
>
>define class MyRoom as container
>  add object "Detector" as MyShape
>enddefine
>
>define class MyShape as shape
>  procedure init
>    with this
>      .borderstyle=0
>      .backstyle=0
>    endwith
>  endproc
>
>  procedure this.click
>    wait window "You clicked me!"
>  endproc
>enddefine
>
>
>So only the first set of code works, the other two not. What's wrong with them? No matter how, I only want to pass paramter to the class definitin such that I can determine which shape is clicked, any help please?
>
>Thanks in advance!
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Reply
Map
View

Click here to load this message in the networking platform