?
Solved

please help me thread my app.

Posted on 2004-09-22
5
Medium Priority
?
157 Views
Last Modified: 2010-04-05
I have an app that would VASTLY benefit from 30+ threads.   It is on one form.  I have a start and stop button that set "stopper" var.   While stopper is false, the app will fire one of 2 procedures.  These are nearly identical.    One uses one dataset (clientdataset1) and the other users 2 datasets (clientdataset1 and clientdataset2)  I will only be using one at a time and never in the same session.  I personally have never used threads and get severely confused when reading about them as the verbage is unfamiliar to me.  the issues that would seem to be tough are teh dataset access and the reporting of status to the main form.  

Please give as detailed an answer as you can, although I appreciate that this is not an easy question.

Andrew
0
Comment
Question by:hibbidiji
[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
5 Comments
 
LVL 2

Expert Comment

by:__alex
ID: 12130451
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12130529
if the DataSet from the first thread is one of the DataSets in the second thread ... you have to use CriticalSection...
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 2000 total points
ID: 12130550
// THREAD EXAMPLE
// -----------------------------

TTestThread = class(TThread)
private
  LocalDataSet   : TClientDataSet;
public
  IsFinished     : Boolean;
  constructor Create(CreateSuspended : Boolean; DS : TClientDataSet);
  procedure Execute; override;
end;


constructor TTestThread.Create(CreateSuspended: Boolean;
  DS: TClientDataSet);
begin
  // create the thread
  inherited Create(CreateSuspended);
  // pass the dataset locally
  LocalDataSet := DS;
  // init
  IsFinished := False;
end;

procedure TTestThread.Execute;
begin
  inherited;
  // Access the DS here
  // do something with it here...

  IsFinished := True;
end;

// EXAMPLE HOW YOU CALL IT
// ----------------------------------

procedure TForm1.Button1Click(Sender: TObject);
var
  tr      : TTestThread;
begin
  tr := TTestThread.Create(False, ClientDataSet1);
  while not tr.IsFinished do
    Application.ProcessMessages;
end;
0
 
LVL 6

Expert Comment

by:vadim_ti
ID: 12133936
1)DataSets

i think better way is to work with 3 datasets

thread A: clientdataset1A
thread B: clientdataset1B and clientdataset2B

this way you do not need to use critical sections

2)reporting of status to the main form

you can use
   PostMessage(MainForm.Handle, YOUR_MESSAGE, wParam, lParam)



0
 
LVL 1

Author Comment

by:hibbidiji
ID: 12139458
hard but not impossible. thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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
Course of the Month11 days, 22 hours left to enroll

752 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