?
Solved

Event from user control not finding variable values in class

Posted on 2001-06-21
9
Medium Priority
?
146 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 400 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
Technology Partners: 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

762 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