Solved

Event from user control not finding variable values in class

Posted on 2001-06-21
9
139 Views
Last Modified: 2013-11-25
Hi.  I'm trying to create a DLL to communicate to a serial device.  I have the communications working, but now they want to implement a function which requires a timer.  I perform 1 write to the device and set the wait duration variable in the timer event.  The timer event should call the same function only with different variables.  All seems to be going well, but when the timer event fires in the form it calls a function from the device class.(Dataliner.DisplayPermMsg)
When I step through the code after the timer event, I find that the properties in the class that had been set previously are now all empty strings.  It is like a new instance of the class has been created and nothing is initialized.  The function passed the empty strings instead of the required values and the code completes.
When I send the next message though without using the timer, the previously set class properties are what they should be.  I think I'm missing something small, but its stopping the whole thing.  I have this same problem with using the DataArrival event of a winsock control and firing procedures or events in another class.  Both applications are DLL's. Is there something special about firing events or functions in a class that is part of a DLL?   Any and all information to fix this problem would be appreciated.
0
Comment
Question by:Dant
9 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6216522
can you post where you are declaring your instance of the class within the dll, and how you are calling it?  maybe just a small pseudo template so we can get an idea of your code structure...
0
 
LVL 5

Expert Comment

by:gbaren
ID: 6216598
You should declare any variables that you want to persist between timer events outside of the Timer routine. They should be declared at the top of the form module.

---
Option Explicit

DIM Persistent_Var as String

Sub Timer1_Timer()

    Text1 = MyFunction(Persistent_Var)

End Sub

0
 
LVL 22

Accepted Solution

by:
CJ_S earned 100 total points
ID: 6217709
You should NEVER use properties / variables when creating a component. When you bind a variable to a component it does not create the instance right away...it will be created in the first function call to the object.

You should create your functions in such a way that you pass it all variables. It happens quite often that a component will be freed from the memory it was using, even though the reference count (underlaying the IUnknown AddRef and IUnknown Release) will be more than 0 (ie. more than one reference), but still it will free the memory.

Regards,
CJ
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6217714
The story above especially counts for components created for MTS...it is called Just In Time Activation.

regards,
CJ
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 49

Expert Comment

by:DanRollins
ID: 7139670
Hi Dant@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept CJ_S's comment(s) as an answer.

Dant@devx, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7174009
Comment from expert accepted as expert

Computer101
E-E Moderator
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7174016
Thank you!
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7174018
Comment from expert accepted as expert


*LOL* ;-)
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7174038
oops
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now