Graeme Geldenhuys schreef:
Hi,

I have a worker thread that calculates a crc values of a file. My
application maintains a maximum of 10 such threads at a time (though
the user can adjust the maximum value).  Each thread is represented by
a progress bar on the main form of the application.

Under Delphi my worker thread could post a message using (PostMessage)
to notify the main form about the progress of the worker thread and
the max value the progress bar should be set at when starting.

How do I manage this under Lazarus. Note the application must be able
to run under Linux and Windows (where before it was only Delphi /
Windows).

The Object Pascal language, as implemented by Free Pascal understands
the  'message' declaration in a class, but how do I use it in a
cross-platform way?  How do I send such custom messages?

For example;
----------------------------------------

interface
uses
 ...
 LMessages;

const
 UM_PROGRESS = WM_USER + 1;
 UM_SETTEXT = WM_USER + 2;
 UM_SETMAX = WM_USER + 3;

type
 TMainForm = class(TForm)
 [....]
 protected
   procedure UMProgress(var Message: TMessage); message UM_PROGRESS;
   procedure UMSetText(var Message: TWMSetText); message UM_SETTEXT;
   procedure UMSetMax(var Message: TMessage); message UM_SETMAX;
 [....]

----------------------------------------

And this is how I used to send messages from the worker threads. This
example notified the main form what the progressbar's max value must
be set at - for the associated thread.

     PostMessage(FHandle, UM_SetMax, integer(pointer(FProgressBar)),
FMaxValue);



Redesign it a bit.

The simplest is to pass a reference to your mainform to the worker threads. In the worker threads call the Progress method. Make sure you do it synchronized.

Is this clear enough, or do I need to give an code example?

Vincent

P.S. How are the stylesheets going?

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to