Solved

components

Posted on 2000-04-29
6
226 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:liuxiao
6 Comments
 
LVL 2

Expert Comment

by:hhamster
ID: 2762882
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.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2762912
You should create the progress bar like this:

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

Cheers,

Raymond.
0
 

Expert Comment

by:miche
ID: 2762919
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.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:liuxiao
ID: 2762965
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.

0
 
LVL 2

Accepted Solution

by:
Ten13 earned 50 total points
ID: 2764903
Hi

To own and display a visual component from within a TComponent do like this:

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
procedure TMyComponent.CreatePrograssBar
begin
  inherited Loaded;
  if Owner.InheritsFrom(TForm) then begin // check that we are placed on a form and not a data module or other
    FMyProgressBar:= TProgressBar.Create(Owner);
    with FMyProgressBar do begin
      Parent:= TWinControl(self.Owner);
      Left:= 5;
      Top:= 5;
      // and so forth
      Visible:= true; // might (not) be nessisary!?!
    end;
  end;
end;

if you need the progressbar right away you might want to create it in the Loaded procedure of yout component:
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
procedure TMyComponent.Loaded; // override
begin
  inherited Loaded;
  CreatePrograssBar;
end;

and delete it in Destroy:
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
destructor TMyComponent.Destroy; // override
begin
  FMyProgressBar.Free;
  inherited Destroy;
end;

Hope this is what you are looking for. Good luck!

- Martin
0
 

Author Comment

by:liuxiao
ID: 2765215
thanks ten!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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