|
Home > Archive > FoxPro Help and Support > May 2005 > How I can run a code later I call a Class
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How I can run a code later I call a Class
|
|
| Javier 2005-05-25, 8:25 pm |
| Hi, I want to know how is possible to run a code in a button that belong to a
class, something like:
**
cmdEdit::click
My Code......
**
When I try in my own class this message is showed:
The current object does not inherit from class MyClass
Thanks for help me.
| |
| Paul Pedersen 2005-05-25, 8:25 pm |
| You don't run code from a class, you run code from an instantiated object.
For instance,
myVar = CREATEOBJECT("myclass")
....
(in some button's click method) myvar.somemethod()
"Javier" <Javier@discussions.microsoft.com> wrote in message
news:1EF806FD-D0F6-4821-BA68- 4D1EEC61C63B@microso
ft.com...
> Hi, I want to know how is possible to run a code in a button that belong
> to a
> class, something like:
>
> **
> cmdEdit::click
>
> My Code......
> **
>
> When I try in my own class this message is showed:
>
> The current object does not inherit from class MyClass
>
> Thanks for help me.
| |
| Javier 2005-05-26, 1:24 pm |
| Thanks Paul, but can you explain me more, because I don't understand your
answer.
Javier
"Paul Pedersen" escribió:
> You don't run code from a class, you run code from an instantiated object.
>
> For instance,
>
> myVar = CREATEOBJECT("myclass")
>
> ....
>
> (in some button's click method) myvar.somemethod()
>
>
>
>
>
>
>
> "Javier" <Javier@discussions.microsoft.com> wrote in message
> news:1EF806FD-D0F6-4821-BA68- 4D1EEC61C63B@microso
ft.com...
>
>
>
| |
| Paul Pedersen 2005-05-26, 8:25 pm |
| That's fair, because I don't really understand your question either.
Post your code, and I'll try to figure out why it doesn't work.
"Javier" <Javier@discussions.microsoft.com> wrote in message
news:38076DB7-523C-4514-98F4- 407ED59077F3@microso
ft.com...[color=darkred]
> Thanks Paul, but can you explain me more, because I don't understand your
> answer.
>
> Javier
>
> "Paul Pedersen" escribió:
>
| |
| Cindy Winegarden 2005-05-26, 8:25 pm |
| Hi Javier,
Let's assume you've got a form named Form1 with a button named Button1.
Elsewhere in your project you've got a class named MyClass that looks like
the following:
*-- Code In MyPrg.prg
Define Class MyClass As Custom
Procedure ShowMessage(tcMessag
e)
MessageBox(tcMessage
)
EndProc
EndDefine.
Before you can call MyClass.ShowMessage("HelloWorld") from Button1's Click()
you've got to have an instance of MyClass somewhere in scope. To do that you
could put code in Button1 like the following:
*-- Button1.Click()
Set Procedure To MyPrg.prg
oMyClass = CreateObject("MyClass")
oMyClass.ShowMessage("HelloWorld")
Alternatively MyClass can be a visual class. You'd need to Set ClassLib To
.... before creating an instance of MyClass.
If this doesn't get you started, as Paul said, post the code you've got so
far and we'll see what's happening.
--
Cindy Winegarden MCSD, Microsoft Visual Foxpro MVP
cindy_winegarden@msn
.com www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden
"Javier" <Javier@discussions.microsoft.com> wrote in message
news:1EF806FD-D0F6-4821-BA68- 4D1EEC61C63B@microso
ft.com...
> Hi, I want to know how is possible to run a code in a button that belong
> to a
> class, something like:
>
> **
> cmdEdit::click
>
> My Code......
> **
>
> When I try in my own class this message is showed:
>
> The current object does not inherit from class MyClass
>
> Thanks for help me.
|
|
|
|
|