Solved

components

Posted on 2000-04-29
6
221 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:liuxiao
Comment Utility
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
Comment Utility
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
Comment Utility
thanks ten!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now