?
Solved

ActiveForm with ThreadedTimer

Posted on 2003-03-02
5
Medium Priority
?
364 Views
Last Modified: 2010-04-04
Greetings,

Can someone tell me why this doesn't work? I've been trying to work this out and getting nowhere.

I'm having problems when trying to use threading on an ActiveForm (D7 on XP Pro). For a simple test, I created a new ActiveForm project and added a TMemo and ThreadedTimer (one I picked up on Torry's) to the form.

On the form's OnCreate I enable the timer. On the OnTimer event for the threaded timer component I add a line to the memo:

Memo1.Lines.Add('timer');

I use Web Deploy, then launch the resulting htm file in IE. The memo shows as expected but the memo never has any lines added.

If I replace the ThreadedTimer component with Delphi's standard TTimer and recompile, the ActiveForm works fine.

I have been trying to convert an existing app to ActiveForms for use in MMC. As I was doing this I found that anywhere I was using threads was not working.

Thanks - Eric

0
Comment
Question by:epaulson
[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
  • 3
5 Comments
 
LVL 2

Expert Comment

by:CSJ
ID: 8056178
I am not familiar with the ThreadedTimer you found on Torry's.  However, when using objects from the VCL object hierarchy, their properties/methods are not necessarily thread-safe.  Try using the method Synchronize - this waits for the main VCL thread to enter the message loop and then executes the passed method:

procedure TMyThread.UpdateMemo;
begin
  mainForm.Memo1.Lines.Add('timer');
end;

procedure TMyThread.OnTimer(Sender: TObject);
begin
  Synchronize(UpdateMemo);
end;

Hope this helps

Floyd
0
 

Author Comment

by:epaulson
ID: 8067121
Floyd,

Thanks for the suggestion! I will try this out and report back.

Eric
0
 

Author Comment

by:epaulson
ID: 8146350
Sorry for the delay. Unfortunately I am covered as far as using the Sychronize method for the thread.

I have been unable to determine why doing this on an ActiveForm just doesn't work. If I do everything the same on a standard Delphi form it works fine. It seems that when using an ActiveForm that there must be something additional required to get this to work. I did experiment a bit to determine that the thread had a valid handle and that the timer was actually starting, but still no luck.

I am probably going to give up on doing it this way and look into using a separate DLL rather than threading.

Thanks

Eric
0
 

Author Comment

by:epaulson
ID: 8187028
I figured it out! The key was to not use synchronize. I stumbled on this by experimenting with using the CreateThread API call and found I could get a thread to work in this manner. I took it a step further on my test program by creating a TThread. With the Synchronize(procedure) the thread would never execute properly, but worked fine without Synchronize. Since I am just using the thread to run a process without locking up my app, this will do just fine.

Eric
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8187368
PAQ'd and 200 points refunded

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
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