Solved

make Dialog box a component

Posted on 2003-11-26
3
255 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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

10 Experts available now in Live!

Get 1:1 Help Now