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
Solved

please help me thread my app.

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 119
How to define IfThen functions in one common unit? 4 60
Delphi Yen format 3 45
tvirtualstringtree freeze when load too manny images 10 71
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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