[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

components

Posted on 2000-04-29
6
Medium Priority
?
230 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

649 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