April 26, 2024, 09:56:00 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Multiple instanance of Class?

Started by LarryMc, July 10, 2007, 03:29:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

Scenario:
I have a Class (clas) with methods and member variables.
Some of the methods in the Class call other methods in the class internally.

I have project with multiple src files.

I define a variable MyClass1 as global and declare it of type clas in my main src file.
In the other src files I declare it as extern.

I define a variable MyClass2 as global and declare it of type clas in my $main src file 1.
In the other src files I declare it as extern.

I call methods in MyClass1 in a subroutine in src file 2 repeatedly with problem.

I call methods in MyClass2 in a dialog handler in src file 3. No errors.

But, after calling MyClass2 that one time, calls to MyClass1 no longer return proper results. Ajnd I never get proper results again until I restart the program.

Question:  Could the 2 different instances be cross feeding into each other somehow?
Could it be doing so because I did not use THIS for any of the internal calls to other methods or for references to the member variables?

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Really would need to see the classes.
Ionic Wind Support Team

LarryMc

July 10, 2007, 09:42:20 PM #2 Last Edit: July 10, 2007, 09:50:04 PM by Larry McCaughn
Sent source to my class to your email address as an attachment.
There's only one class but 2 variables.

in $Main src
global clas1
global clas2
def clas1 as CXmlLM
def clas2 as CXmlLM


in the other src files
extern clas1:CXmlLM
extern clas2:CXmlLM


I'm crossing source file boundaries
I'm using the methods inside subroutines and dialog msg handlers.

Works fine in a dummied up console project where I going back and forth between src files and subroutines.

The only thing I haven't dummied up is the dialog aspect.


Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Paul,
Seems the problem isn't so much multiple instances but more a problem with the interaction through a dialog.

A user of my class lib has the same symptoms with his program he posted at http://www.ionicwind.com/forums/index.php/topic,1603.msg16216.html#msg16216

I changed his program from a global defining of the class instance to defining it dynamically inside a subroutine and it worked correctly.

I even changed his program to create the class instance dynamically inside the dialog msg handler and it worked fine.

There's just something that isn't kosher between globally defining a class instance and passing through a dialog to a subroutine to call some of its methods.

Calling subroutine(s) from subroutine(s) ; and calling methods in global instance; seems to work fine.  It's just that dialog thing.

But it needs to work with the global instance so that the methods can be called from multiple places to operate on the same data that the class handles.

I don't have a clue.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Found my problem.

Paul has preached and preached about being careful of null pointers.

My problem wasn't null pointers but pointers with the wrong values in them; which I think is worse.

At any rate the problem appears to be fixed by me modifying my class library which I posted at

http://www.ionicwind.com/forums/index.php/topic,1603.msg15670.html#msg15670

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Also known as unitialized variables ;)

Ionic Wind Support Team

LarryMc

Quote from: Paul Turley on July 11, 2007, 08:29:15 PM
Also known as unitialized variables ;)
Yep!
Left over dregs values from the last pass through.
Took me 3 days to find it.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

REDEBOLT

Same old, same old.
The times, they are a changin'
but the bugs never do.
I've spent half my life tracking
down other people's uninitilized
variables.
;D
Regards,
Bob

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library