It's ok, but when I use this.AddObject("cc", "MyClass") at next time to
create same or another object,
I get error message "A member object with this name already exists."
I test this.cc.Destroy(), but with the same effect.
Can anyone help me ?
Thanks
Martin
PS: Sorry, my english is bad, but I learn and learn and .....
First of all, Martin, why not just leave the object on the form? Why
do you have to RemoveObject("the object") at all?
>It's ok, but when I use this.AddObject("cc", "MyClass") at next time to
>create same or another object,
>I get error message "A member object with this name already exists."
Clearly, the RemoveObject isn't working for some reason. I would
guess it's because your THIS.RemoveObject() isn't at the right level.
You may or may not get an perceptible error when you use
RemoveObject() and it doesn't work, depending on a lot of things that
are probably not relevant here <s>.
Before you do your THIS.AddObject(), you can check for the object's
existance. Most people will tell you to check for the existance of an
object like this:
IF TYPE("THIS.cc") = "O" AND NOT ISNULL(THIS.cc)
* -- object exists
ELSE
* -- create it
ENDIF
... however I usually prefer the following test:
IF TYPE("THIS.cc.BaseClass") = "C"
* -- object exists
* etc...
... this is a little less intuitive, I suppose, but a little quicker.
One thing I'm wondering about, to explain why your AddObject() fails::
is it possible that you were doing the first half of the
"usually-recommended" test but not the second? IOW, could you actually
have an instance variable THIS.cc that exists although it may not
reference a member object in all cases?
> I test this.cc.Destroy(), but with the same effect.
Yes, this is true. As a separate issue to what we're discussing, you
should understand that running the Destroy method (the code you've
written into .Destroy()) is not the same as causing the Destroy event
<s>. The object will not disappear just because you call this code.
> PS: Sorry, my english is bad, but I learn and learn and ....
Don't worry about it -- we'll figure this out <s>.
Best,
>L<
> First of all, Martin, why not just leave the object on the form? Why
> do you have to RemoveObject("the object") at all?
My idea: application, based on only one form. (for example: MS Money)
All data processing code (grids, textboxes, listboxes..) is written in
classes, based on container.
Only one of this classes can be active (of course visible), and too much
classes exists. (Input and edit data, queries, ...)
When I create the form, object "cc" (Current Class) not exists. I
initialize it in "InitEvent". (AddObject("cc", ...))
and in all other methods use "cc" to pointer to currently active class. In
one way of run time, "cc" may be pointer to input data container, in
another pointer to preview of SQL query.
Is this wrong way ?
Debugger - watch window - name: "this.cc" :
main form is created - "expression could not be evaluated" - OK
object "cc" is created - preview of "cc" object (all members of container
class) - OK
object "cc" is removed - "expression could not be evaluated" - OK
Both values (when create form and remove object) are identical - exist the
object "cc" or no ?
I don't know to understand this.
Thanks
Martin
>Please IGNORE all what I wrote about RemoveObject.
>The problem not in VFP but in me.
Hi Martin,
I am glad you found your problem, but I hope you read what I wrote
anyway <s>. Although what you are doing is not "wrong" I think there
are better ways. Meanwhile, if you want to go on doing it the way you
are doing it, then the checks I suggested for the existance of an
object will be of use to you eventually <s>.
Best,
>L<
> , then the checks I suggested for the existance of an
> object will be of use to you eventually <s>.
Yes, the object can be used in this way, but...
In the form (top level object) I create new method to add/remove subojects
PROC thisform.AddMyClass
para MyClass
thisform.RemoveObject("cc") && object "cc" is initialized in InitEvent
thisform.AddObject("cc", MyClass)
ENDPROC
When AddMyClass is calling from form, it's ok. When thisform.AddMyClass is
calling from subclass,
object is NOT removed and NO ERROR generated ! Of course, next line
(AddObject) cannot be executed, because
object which the same name really exist.
Another way:
InitEvent declare pointer to subclass: public s_pointer (or add new
property...) and create cursor of
class history.
PROC thisform.AddMyClass
para MyCLass
thisform.&cc..Enabled = .F.
thisform.&cc..Visible = .F.
m.s_pointer = "cc" + alltrim( str( recc("history") + 1 ) )
insert into history (name, class) values (m.s_pointer, m.MyClass)
thisform.AddObject(m.s_pointer, m.MyClass)
ENDPROC
Objects not removed, but at any time is backusing existing class possible.
(Objects can be removed at next time when AddMyClass is calling - is not
active)
That's all. (Uff, it's difficult to understand me... -:) )
Martin
Lisa, I cant write what I can express.
I send you example to your email.
It's OK ?
Martin
>Yes, the object can be used in this way, but...
>In the form (top level object) I create new method to add/remove subojects
>PROC thisform.AddMyClass
> para MyClass
> thisform.RemoveObject("cc") && object "cc" is initialized in InitEvent
> thisform.AddObject("cc", MyClass)
>ENDPROC
>When AddMyClass is calling from form, it's ok. When thisform.AddMyClass is
>calling from subclass,
>object is NOT removed and NO ERROR generated !
I hate to say this but this relly may be your bug <g>. It would
depend on exactly when and how thisform.AddMyClass is called, I
suppose. You really should do the TYPE() check -- are you saying you
don't want to, or that it didn't work in this situation, or what?
>Another way:
>InitEvent declare pointer to subclass: public s_pointer (or add new
>property...) and create cursor of
>class history.
>Objects not removed, but at any time is backusing existing class possible.
>(Objects can be removed at next time when AddMyClass is calling - is not
>active)
Again it looks like what really matters is exactly *when* you are
calling this function. Like the object doesn't really exist yet at
the time you're making the call...
When you say that the object cc is "initialized" in the Init, exactly
how are you doing that?
Best,
>L<
>Lisa, I cant write what I can express.
>I send you example to your email.
>It's OK ?
No, Martin, it's not okay!
I'm sorry, but I consult to Fox developers and I reserve e-mail for my
clients <s>.
If you can create a short example in code and post it in public
**HERE** I will be happy to look at it for you. But here is where I
do **all** my volunteer work. Please don't e-mail me anything.
You don't need to describe it in English. Just write a short runnable
sample in code and post it here.
That goes for anybody else listening, too: I do the best I can to help
you, but please don't mail me samples or requests for private help
unless you'd like to arrange billing terms with me <s>.
Best,
>L<