Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

please help me thread my app.

Posted on 2004-09-22
5
Medium Priority
?
161 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

610 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