?
Solved

components

Posted on 2000-04-29
6
Medium Priority
?
229 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
[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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 200 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 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