Solved

make Dialog box a component

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: how to send PJL commands to printer 3 108
When I am typing into a TEdit last word repeats 7 145
control image tags in a string ? 12 142
update joined tables 2 55
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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