Solved

Event from user control not finding variable values in class

Posted on 2001-06-21
9
144 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 144
Macro Excel - Multiple If conditions 2 92
Help with retrieving partial value from a column using VB.NET 4 57
Export Data to Different .csv Files 27 131
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The viewer will learn how to implement Singleton Design Pattern in Java.
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.

739 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