Solved

make Dialog box a component

Posted on 2003-11-26
3
256 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
3 Comments
 

Accepted Solution

by:
ChrisLM earned 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

24 Experts available now in Live!

Get 1:1 Help Now