Solved

make Dialog box a component

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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