Link to home
Start Free TrialLog in
Avatar of liuxiao
liuxiao

asked on

components

I create a non-visual component, it works well. I want add a processBar on when some code run. question is 'how to arrang the owner and parent of the processBar', I think I must assign them to the form which the component is on, but I cannot do it.
Avatar of hhamster
hhamster
Flag of Croatia image

Create an OnProgressChange Event of the control, which can then arrange some progress bar on the form.

The event should grow from 0 till 100 (what means percentage), and then on the conntrols On that event trigger you can write the code for changing the progres bar.
Avatar of rwilson032697
rwilson032697

You should create the progress bar like this:

  TheProgressBar := TProgressBar.Create(TheForm); // This will set the owner property
  TheProgressBar.Parent := TheForm;

Cheers,

Raymond.
Hi:

 Try something like this

 TProgressEvent = procedure (Sender: TObject; Progress: integer) of object;

 TExample = class(TComponent)
   private
    FOnProgress: TProgressEvent;
   ..........
    procedure SomeThing;
   ..........
  published
   property OnProgress: TProgressEvent read FOnprogress write FOnProgress
 end;

 procedure TExample.Something
 begin
  .......
  // value is progress value
  if Assigned(FonProgress) then FOnProgress(self, value)
 end;


And in your program

 procedure DoProgress(Sender: TObject; Progress: integer);

var
 c: TExample;
 Pb: TProgressBar;
.......
 c.OnProgress:= DoProgress
.......

 procedure TMainForm.DoProgress(Sender: TObject; Progress: integer);
 begin
  ....
  Pb.Position:= Progress;
  ...
 end;

 Or like this

 TExample = class(TComponent)
   private
    FOnProgress: TProgressEvent;
    FProgressBar: TProgressBar;
   ..........
    procedure SomeThing;
   ..........
  published
   property OnProgress: TProgressEvent read FOnprogress write FOnProgress
   property ProgressBar: TProgressBar read FProgressBar write FProgressBar;
 end;

 procedure TExample.Something
 begin
  .......
  // value is progress value
  if Assigned(FProgressBar) then FprogressBar.Position:= value;
  if Assigned(FonProgress) then FOnProgress(self, value)
 end;


Regards,
Miche.
Avatar of liuxiao

ASKER

My component uesed by another developer,
I cannot write any code on his(her) program like:

 procedure TMainForm.DoProgress(Sender: TObject; Progress: integer);
 begin
  ...
end;

And I also cannot enforce him(her) write an event.

I means all of jobs like processBar create, display on a right position and free done by component itself.

But a non-visual component can own a processBar but cannot show it.
So I should arrange another owner.

ASKER CERTIFIED SOLUTION
Avatar of Ten13
Ten13
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of liuxiao

ASKER

thanks ten!