Solved

please help me thread my app.

Posted on 2004-09-22
5
149 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
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now