• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

How-To-Turn-That-Form-I-Customized-Into-A-Component-That-Can-Be-Installed-Onto-Delphi's-Palette?

Hi Delphianz!

Who is patient enough to walk me through the How-To-Turn-That-Form-I-Customized-Into-A-Component-That-Can-Be-Installed-Onto-Delphi's-Palette-So-I-Can-Use-It-As-A-Dialog-In
My-Other-Projects-Thingie?

// I edited this question or updated it so in case you wonder something changed you dont have to doubt :)


interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,
  Forms, Menus, Dialogs, StdCtrls,
  ExtCtrls;

type
  TMyErrorDialog = class(TComponent)
    GroupBox1: TGroupBox;
    lblMessage: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    lblLine: TLabel;
    lblMethod: TLabel;
    lblUnit: TLabel;
    lblAddress: TLabel;
    chkRestart: TCheckBox;
    btnOK: TButton;
    btnSend: TButton;
    procedure btnOKClick(Sender: TObject);
    procedure btnSendClick(Sender: TObject);
  private
    { Private declarations }
  protected
    { Protected declarations }
    procedure SetCaption(newValue: TCaption); virtual;
    function GetCaption: TCaption; virtual;
    procedure SetFont(newValue: TFont); virtual;
    function GetFont: TFont; virtual;
    procedure SetWordWrap(newValue: Boolean); virtual;
    function GetWordWrap: Boolean; virtual;
    procedure SetCursor(newValue: TCursor); virtual;
    function GetCursor: TCursor; virtual;
    procedure SetHint(newValue: String); virtual;
    function GetHint: String; virtual;
    procedure SetChecked(newValue: Boolean); virtual;
    function GetChecked: Boolean; virtual;
    procedure SetShowHint(newValue: Boolean); virtual;
    function GetShowHint: Boolean; virtual;
    procedure SetState(newValue: TCheckBoxState); virtual;
    function GetState: TCheckBoxState; virtual;
    procedure SetModalResult(newValue: TModalResult); virtual;
    function GetModalResult: TModalResult; virtual;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Caption: TCaption read GetCaption write SetCaption;
    property Font: TFont read GetFont write SetFont;
    property WordWrap: Boolean read GetWordWrap write SetWordWrap;
    property Cursor: TCursor read GetCursor write SetCursor;
    property Hint: String read GetHint write SetHint;
    property Checked: Boolean read GetChecked write SetChecked;
    property ShowHint: Boolean read GetShowHint write SetShowHint;
    property State: TCheckBoxState read GetState write SetState;
    property ModalResult: TModalResult read GetModalResult write SetModalResult;
  end;

procedure Register;


implementation

{$R *.DFM}

 uses ShellApi;

constructor TMyErrorDialog.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

destructor TMyErrorDialog.Destroy;
begin
  inherited Destroy;
end;

procedure Register;
begin
  RegisterComponents('Standard', [TMyErrorDialog]);
end;

procedure TMyErrorDialog.btnOKClick(Sender: TObject);
begin
  if chkRestart.Checked then
    ShellExecute(0, nil, PChar(Application.ExeName), nil, nil, SW_NORMAL);
  ModalResult := mrOK;
end;

procedure TMyErrorDialog.btnSendClick(Sender: TObject);
begin
  ShowMessage('E-Mail has been sent.');
end;


procedure TMyErrorDialog.SetCaption(newValue: TCaption);
begin
  lblMessage.Caption := newValue;
  Label1.Caption := newValue;
  Label2.Caption := newValue;
  Label3.Caption := newValue;
  Label4.Caption := newValue;
  Label5.Caption := newValue;
  Label6.Caption := newValue;
  chkRestart.Caption := newValue;
  btnOK.Caption := newValue;
  btnSend.Caption := newValue;
end;  

function TMyErrorDialog.GetCaption: TCaption;
begin
  GetCaption := lblMessage.Caption;
end;  

procedure TMyErrorDialog.SetFont(newValue: TFont);
begin
  lblMessage.Font := newValue;
  Label1.Font := newValue;
  Label2.Font := newValue;
  Label3.Font := newValue;
  Label4.Font := newValue;
  Label5.Font := newValue;
  Label6.Font := newValue;
  chkRestart.Font := newValue;
  btnOK.Font := newValue;
  btnSend.Font := newValue;
end;  

function TMyErrorDialog.GetFont: TFont;
begin
  GetFont := lblMessage.Font;
end;

procedure TMyErrorDialog.SetWordWrap(newValue: Boolean);
begin
  lblMessage.WordWrap := newValue;
end;

function TMyErrorDialog.GetWordWrap: Boolean;
begin
  GetWordWrap := lblMessage.WordWrap;
end;

procedure TMyErrorDialog.SetCursor(newValue: TCursor);
begin
  chkRestart.Cursor := newValue;
  btnOK.Cursor := newValue;
  btnSend.Cursor := newValue;
end;  

function TMyErrorDialog.GetCursor: TCursor;
begin
  GetCursor := chkRestart.Cursor;
end;  

procedure TMyErrorDialog.SetHint(newValue: String);
begin
  chkRestart.Hint := newValue;
  btnOK.Hint := newValue;
  btnSend.Hint := newValue;
end;

function TMyErrorDialog.GetHint: String;
begin
  GetHint := chkRestart.Hint;
end;  

procedure TMyErrorDialog.SetChecked(newValue: Boolean);
begin
  chkRestart.Checked := newValue;
end;

function TMyErrorDialog.GetChecked: Boolean;
begin
  GetChecked := chkRestart.Checked;
end;

procedure TMyErrorDialog.SetShowHint(newValue: Boolean);
begin
  chkRestart.ShowHint := newValue;
  btnOK.ShowHint := newValue;
  btnSend.ShowHint := newValue;
end;  

function TMyErrorDialog.GetShowHint: Boolean;
begin
  GetShowHint := chkRestart.ShowHint;
end;

procedure TMyErrorDialog.SetState(newValue: TCheckBoxState);
begin
  chkRestart.State := newValue;
end;  

function TMyErrorDialog.GetState: TCheckBoxState;
begin
  GetState := chkRestart.State;
end;  

procedure TMyErrorDialog.SetModalResult(newValue: TModalResult);
begin
  btnOK.ModalResult := newValue;
  btnSend.ModalResult := newValue;
end;  

function TMyErrorDialog.GetModalResult: TModalResult;
begin
  GetModalResult := btnOK.ModalResult;
end;

end.

  RegisterComponents('Standard', [TMyErrorDialog]);
end;

end.
 


My points....for your patience :)

Regards Peter
0
PeterdeB
Asked:
PeterdeB
  • 12
  • 8
1 Solution
 
PeterdeBAuthor Commented:
>>>  just got my hands on the form > by 'adding' the unit to my package instead of simply writing its name in the uses clause....:)

Peter
0
 
PeterdeBAuthor Commented:
Am I on the right track?
   >>>>>

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,
  Forms, Menus, Dialogs, StdCtrls,
  ExtCtrls;

type
  TMyErrorDialog = class(TComponent)
    GroupBox1: TGroupBox;
    lblMessage: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    lblLine: TLabel;
    lblMethod: TLabel;
    lblUnit: TLabel;
    lblAddress: TLabel;
    chkRestart: TCheckBox;
    btnOK: TButton;
    btnSend: TButton;
    procedure btnOKClick(Sender: TObject);
    procedure btnSendClick(Sender: TObject);
  private
    { Private declarations }
  protected
    { Protected declarations }
    procedure SetCaption(newValue: TCaption); virtual;
    function GetCaption: TCaption; virtual;
    procedure SetFont(newValue: TFont); virtual;
    function GetFont: TFont; virtual;
    procedure SetWordWrap(newValue: Boolean); virtual;
    function GetWordWrap: Boolean; virtual;
    procedure SetCursor(newValue: TCursor); virtual;
    function GetCursor: TCursor; virtual;
    procedure SetHint(newValue: String); virtual;
    function GetHint: String; virtual;
    procedure SetChecked(newValue: Boolean); virtual;
    function GetChecked: Boolean; virtual;
    procedure SetShowHint(newValue: Boolean); virtual;
    function GetShowHint: Boolean; virtual;
    procedure SetState(newValue: TCheckBoxState); virtual;
    function GetState: TCheckBoxState; virtual;
    procedure SetModalResult(newValue: TModalResult); virtual;
    function GetModalResult: TModalResult; virtual;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Caption: TCaption read GetCaption write SetCaption;
    property Font: TFont read GetFont write SetFont;
    property WordWrap: Boolean read GetWordWrap write SetWordWrap;
    property Cursor: TCursor read GetCursor write SetCursor;
    property Hint: String read GetHint write SetHint;
    property Checked: Boolean read GetChecked write SetChecked;
    property ShowHint: Boolean read GetShowHint write SetShowHint;
    property State: TCheckBoxState read GetState write SetState;
    property ModalResult: TModalResult read GetModalResult write SetModalResult;
  end;

procedure Register;
0
 
mikelittlewoodCommented:
The best thing to do with forms is add them to the repository.

Make your form as normal, with all the functionality you want on it.
Once it is ready, right click on the form and choose "Add to repository".
Give it a title and description and in the Page drop down choose Forms.

Then whenever you create a new application, you can go to the main menu .. File > New Other .. then select the forms tab, select your form and make sure you have Inherit checked.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DeerBearCommented:
Unlike mike, I'd suggest that you keep your form as it is.

Now, Inherit a new class from TCommonDialog, overriding the Execute function(it's the same base class used for TOpenDialog and the likes).

Create  new package, add a registration unit, register the component in the palette and you're done.

You can find LOADS of tutorials on how to do these steps.

Cheers,

Andrew
0
 
PeterdeBAuthor Commented:
Hi Mike,

I'm familiar with the technique you describe and use it extensively. The reason I want to 'component' my form instead of adding it to the object repository is because of my frequent reinstalls of Delphi. Is it possible to save both the repository items and the templates (cause that's the technique I use extensively too) so that I can use them later in with a fresh Delphi install? If so, then I'd like to know how.

Andrew,

I pressume inheriting a class from TCommonDialog equals descending\deriving my component from TCommonDialog, right? So in contrast to what I was doing, deriving from TComponent, I should use TCommonDialog?
Furthermore > the overriding thingie means adding 'virtual' to that procedure, since it already exists, right?
I followed several tuts but stranded every time.


Peter
0
 
PeterdeBAuthor Commented:
Correction > override instead of virtual :)

Peter
0
 
DeerBearCommented:
I think that it's just easier to call the form on demand and have all the rest handled separately, which is the ultimate goal of Object Oriented Programming.

Cheers,

Andrew
0
 
PeterdeBAuthor Commented:
Hi Andrew,

Well whatever the goal may be of OOP, creating my own component is my goal at the moment and succeeding in doing so will surely mean that I've expanded my knowledge regarding programming.
For the moment however I stumble upon the last stage. Creating the package works, creating the descendant of TCommonDialog works. Creating the reg unit works. Compiling this whole thingie even works.....but then...installing fails and I'm struck with the message: 'Cannot find @entrypoint of function Execute in vcl70.bpl'. This might look slightly different but alas, apparently it lacks some information which is vital to the process, and I don't know what.....

Regards,

Peter
0
 
DeerBearCommented:
Uhm... ok, can you post the package source please?
Let's see if there's anything relevant.

Andrew
0
 
PeterdeBAuthor Commented:
Hi Andrew,

Yes I can and as a matter a fact I'm more than happy to do so! :)

Here goes the .dpk file >

// >>>
package dclPDBDlgs;

{$R *.res}
{$R 'dclPDBDlgsReg.dcr'}
{$ALIGN 8}
{$ASSERTIONS OFF}
{$BOOLEVAL OFF}
{$DEBUGINFO ON}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS OFF}
{$RANGECHECKS OFF}
{$REFERENCEINFO OFF}
{$SAFEDIVIDE OFF}
{$STACKFRAMES OFF}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST ON}
{$MINENUMSIZE 1}
{$IMAGEBASE $4480000}
{$DESCRIPTION 'Dialog by Peter de Biel'}
{$DESIGNONLY}                                        < I also tried to compile it with this set to RUNONLY but that didnt seem to matter
{$IMPLICITBUILD ON}

requires DesignIDE,vcl,dclPDBDlgs70,rtl;

contains
  dclPDBDlgsReg in 'dclPDBDlgsReg.pas',uPDBErrorDlg in 'uPDBErrorDlg.pas' {frmErrorDlg},PDBDlg in 'PDBDlg.pas';
end.

the reg unit >>

//
unit dclPDBDlgsReg;
interface
uses
  Classes,
  DesignEditors,
  DesignIntf;
procedure Register;

implementation

{$R dclPDBDlgsReg.dcr}

procedure Register;
begin
RegisterComponents('PDB', [TuPDBErrorDlg]);
end;
0
 
DeerBearCommented:
Why are you using DesignEditors and DesignIntf?

You should place your editors and design time stuff in the designonly package and I don't see why you placed those units in the registration unit.

Cheers,

Andrew
0
 
PeterdeBAuthor Commented:
'Cannot find entrypoint of procedure @Dialogs@TCommonDialog@Execute$qqrv in DLL -file vcl70.bpl'  <<< this is the exact message I now have in front of me.

Regards,

Peter
0
 
PeterdeBAuthor Commented:
Well I didn't place them there deliberately, that is I'm using some program to assist me in this all. I 'simply' defined the name and location of the files, the rest was done automatically and since the compiling went okay I didn't think of anything being wrong with the files that were automatically created.

Peter

Ps The use of several files easily confuses me and the thing I fail to get is adding my form to the package. Yesterday I managed to install some package which was autocreated and made use of the files I posted, the skeleton code that is, the name differed. I installed it and later on when I threw it on a new project it played dead and at every attempt to unhide it it came up with several AV's.
0
 
DeerBearCommented:
It looks like there's some problem with some design-time package.

Try removing the most recently added ones and see what happens.

Cheers,

Andrew
0
 
PeterdeBAuthor Commented:
Hi Andrew,

I just 'managed' to install a component which consisted of an edit box and a button and a simple showmessage procedure. I used it in a new project and just like I expected the properties and stuff were not accessible in design time but the component 'worked' so I think i'm getting the picture bit by bit.

Regards,

Peter
0
 
DeerBearCommented:
Sorry Peter, but I thought you were able to create and install a component.

Ok, let's see a small introduction to component creation.

Your component unit will look like this(USES CLAUSE MISSING, you have to add proper one):

unit MyComp;

interface

Type
 
   TMyDialog = class(TCommonDialog)
   private
     FForm : TMyForm;
   public
     function Execute: boolean;override;
   published
    // properties go here if you want to make them visible
     property MyInt : Integer read FInteger write SetInteger(const Value : Integer);
   end;

implementation

function TMyDialog.Execute : Boolean;
begin
  FForm := TMyForm.Create(Owner);
  // Set properties for the form here
  Result := FForm.ShowModal = mrOk;
  FForm.Free;
end;

Alternatively, you can override create and map form's properties surfacing them in your component.
This is the way to go if you think that your dialog could be called frequently, otherwise it's better to
call everything on-demand, IMHO.

Use CodeCompletion to allow Delphi to complete the class for you(less hassle).

Cheers,

Andrew
0
 
PeterdeBAuthor Commented:
Yesssss!! I just managed to grab hold of the edits caption in design time!! Jieehaaa!! :)

Step by step and bit by bit I AM  GETTING IT!!

Regards,

Peter :)
0
 
DeerBearCommented:
doesn't it feel wonderful when you get it by yourself with some... directions? :-)

Andrew
0
 
PeterdeBAuthor Commented:
Hi Andrew!

Yes it sure does, sometimes all that Delphi stuff is quite overwhelming and when I get fed up with it I always turn to you  guys (and girls ofcourse:). It's incredible to see how much I've learned, certainly given the fact I started two years ago at home without anything more than a lot of spare time to spend and my computer right in front of me. It took me weeks to get that first notepad-alike-thingie to work in Delphi 6 but when I finally managed to get it working I was completely stunned by all Delphi could do. I then messed with Delphi on a regular base and I still enjoy it to the max!

For the time being I still have a lot of spare time and during time I learned to be patient and persistent no matter how long it takes, finally I will achieve my goals....so yes that feels great.....but apart from all the Delphi help I get from here, I also value the gesture itself > helping someone else > it brings me that special feeling of not being entirely on myself and it encourages me to look at our world with slight different perspectives than I did years ago :)

I will now get rid of my points and you may consider yourself the winner :)

Expect some more questions of me regarding the component I created but for now let's rock!!

Regards and muchos gracias!

Peter :)
0
 
PeterdeBAuthor Commented:
Andrew > I only just noticed your post > after I posted mine and I immediately see what I was doing wrong > I was trying to force my form into that component but really had no idea where to place the d*mn thing!

Regards Peter :)

0
 
DeerBearCommented:
Helping others is failry rewarding, yes, especially when you help in the right way :-)

Cheers and thanx for the points,

Andrew
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 12
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now