Solved

Event from user control not finding variable values in class

Posted on 2001-06-21
9
141 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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
 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 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