Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

make Dialog box a component

Posted on 2003-11-26
3
Medium Priority
?
264 Views
Last Modified: 2010-04-05
hi all,

i've tried to create a dialog component based on a form. the code seems fine, it can update property,..... but one serious problem i found that is IT DOES NOT SHOW UP when Execute()is called. Does anyone have ideas??
Below is code segment, pls advise...
thx Alot....

###############################################################################

type
  TComProgress = class(TComponent)
    pgbStatus: TProgressBar;
    lblMsg: TLabel;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure refresh;
  private
    { Private declarations }
    FCaption:String;
    FPMessage: String;
    FMin: Integer;
    FMax: Integer;
    FInterval: Integer;
    FEnableTimer: Boolean;
  public
    { Public declarations }
    Count : Integer;

    constructor Create(AOwner: TComponent); override;
    //destructor Destroy; override;
    function Execute: Boolean;

    procedure UpdateFormCaption(strCaption: String);
    procedure UpdateLabelCaption(strCaption: String);
    procedure SetMaxProgressBar(MaxVal: Integer);
    procedure SetMinProgressBar(MinVal: Integer);
    procedure SetProgressBarInterval(Interval: Integer);
    function UpdateProgressBar: Boolean;
    procedure SetTimer(enable: Boolean);
    function ResetProgressBar: Boolean;

  published
    property Caption: String read FCaption write UpdateFormCaption;
    property PMessage: String read FPMessage write UpdateLabelCaption;
    property Min: Integer read FMin write SetMinProgressBar;
    property Max: Integer read FMax write SetMaxProgressBar;
    property Interval: Integer read FINterval write SetProgressBarInterval;
    property EnableTimmer: Boolean read FEnableTimer write SetTimer;
  end;
var
  ComProgress: TComProgress;

procedure Register;

implementation

{$R *.dfm}

procedure Register;
begin
  RegisterComponents('AAA', [TComProgress]);
end;

constructor TComProgress.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  // Create Timer as subcomponent of Component
  Timer1 := TTimer.Create(Self);
  Timer1.SetSubComponent(True);

  // Create ProgressBar as subcomponent of Component
  pgbStatus := TProgressBar.Create(Self);
  pgbStatus.SetSubComponent(True);
end;

function TComProgress.Execute: Boolean;
begin
  comProgress := TComProgress.Create(Application);
  try
    comProgress.Caption := Self.Caption;
    comProgress.lblMsg.caption := Self.PMessage;
    comProgress.pgbStatus.Max := Self.Max;
    comProgress.pgbStatus.Min := Self.Min;
    comProgress.pgbStatus.Step := Self.Interval;
    comProgress.Timer1.Enabled := Self.EnableTimmer;
    comprogress.FormCreate(Self);
    result := True;
  finally
    //Progress.Free;
  end;
end;

###############################################################################
0
Comment
Question by:lamtl354
[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
3 Comments
 

Accepted Solution

by:
ChrisLM earned 200 total points
ID: 9955306
Hi,
   I got this out of the delphi help file, so you can look there as well. It's under: 'Creating Custom Components' and then 'Making a dialog box a component'.
First make a seperate form that has all your controls, procedures and all the rest of the stuff you need.
Then create a TComponent and add the unit from the form you created above to the uses clause.
Above the 'Implementation' word add:

var
  AboutBox: TAboutBox;

Then add all your necessary properties.
eg
property EnableTimer: Boolean read FEnableTimer write FEnableTimer;

After that add the execute function:
eg
  ComProgress := TComProgressDialog.Create(Application);                  
  try
    with ComProgress do
    begin
      Timer1.Enabled := EnableTimer;
      Result := ShowModal;                            
    end;
  finally
    ComProgress.Free;                                            
  end;

That's it!
Now in your application, add the component and just use the execute procedure.
eg
  ComProgress1.Execute;

--------------------------------------------Unit code should look like this. I think.------------------------------------------
unit ComProgressDlg;

interface
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, ComProgressUnit;

type
  TComProgress = class(TComponent)
  Private
    FEnableTimer: Boolean;
  Public
    function Execute: Boolean;
  Published
    property EnableTimer: Boolean read FEnableTimer write FEnableTimer;
  end;

procedure Register;

var
  ComProgress: TComProgressDialog;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TComProgressDlg]);
end;

function TComProgressDlg.Execute: Boolean;
begin
  ComProgress := TComProgressDialog.Create(Application);                  
  try
    with ComProgress do
    begin
      Timer1.Enabled := EnableTimer;
      Result := ShowModal;                            
    end;
  finally
    ComProgress.Free;                                            
  end;
end;

end.
---------------------------------------------------------------------------------------------------------------------------------
Chris.

I do not take any credit for this code because most of this come from the delphi help file, so you can thank them.
0

Featured Post

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.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

715 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