Solved

Event from user control not finding variable values in class

Posted on 2001-06-21
9
140 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Python 2.7 - French characters 6 59
MS Acccess - Update Field in Table when report is printed 6 43
allswap challenge 6 79
Excel file not created as expected 7 50
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

910 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

24 Experts available now in Live!

Get 1:1 Help Now