At 12:13 PM 3/15/2005, Gerry Bendixen wrote:
Obviously I was not so clear on my goals.
Here's an attempt to provide an example, stripped of all non-essential details. Hopefully I present it correctly.
I have a 'main' unit (Main.pas) with a form. On the form is ProgressBar1 (a TProgressBar component)
I have a 'uses' unit (Unit1.pas) that does processing and the goal is to show the progress of this processing by updating the ProgressBar on the main form.


(1) Type PProgressBar = ^TProgressBar ; //Declare pointer type
(2) Var ProgressBar1Ptr : PProgressBar ; //Declare pointer variable
(3) ProgressBar1Ptr := PProgressBar(ProgressBar1) ; //Assign value to pointer
(4) TProgressBar(ProgressBarPtr).Position := CalculatedBarPosition ;


Line 1 and 2 are visible to both Main and Unit1.
Line 3 is executed in Main to set the value to the pointer.
Line 4 is executed in Unit1 is update the position of the progress bar.

Again, thanks in advance for your attention and any hints,
Gerry B.

All you have to do is pass ProgressBar1 to Unit1, no need to do all this pointer shuffling. In Main.pas, you call some function in Unit1.pas, just pass in the progress bar:


Main.pas:

        { setup for call }
        DoSomethingThatShouldShowProgress (ProgressBar1);

Unit1.pas:

procedure DoSomethingThatShouldShowProgress (foobar: tProgressBar);
begin
foobar.position := 0;
while ... do begin
do some calculating
foobar.position := where I am now
// depending on how tight your loop is and whether you call Windows API,
// you may need a call to application.ProcessMessages here
end;
end;


As an aside (this doesn't really matter to the above), an instance of tProgressBar (such as ProgressBar1) is already a pointer, but that is internal to Delphi.

When I do this sort of thing, I also set up for those cases where I don't want a progress bar (may not be needed in your program), in which case I pass "nil" for the parameter, and in the code have:

        if foobar <> nil then foobar.position := 42;

HTH


Regards,
Sid Gudes
PIA Systems Corporation
[EMAIL PROTECTED]



_______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

Reply via email to