Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


How to write your own components in less than 3 minutes...Component available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi 7.x (or higher)
Category:
Component Writing
Skill Level:
Scoring:
Last Update:
12/01/2008
Search Keys:
delphi delphi3000 article borland vcl code-snippet writing components creating components changing default components
Times Scored:
3
Visits:
1872
Uploader: Frank de Hell
Company:
Reference: http://www.superliegebeest.nl/delphi.php#1
Component Download: http://www.superliegebeest.nl/d7/ecwg.zip
 
Question/Problem/Abstract:
This tutorial was kept as short as possible, since Delphi can be rather overwhelming, and since this is aimed at the beginner adding conceptual support, this tutorial will give you a quick and easy start into writing [modifying] components. It was created after I found out that it was rather easy to write [modify] your own components. It is a very basic tutorial, which I hope will help many people, into making the Delphi programming somewhat more efficient. It is however not the only way, and I think certainly maybe not the best way, but it is the way I use to limit my efforts for repeating tasks, if you are into programming, then you know you can always use your time for different tasks than those you know how to and have to perform again and again. Here is a way to change all of the components you work with, so they provide you exactly with what you want saving you time!
Answer:



Easy Component Writing Guide
  

Quick Start


This little tutorial will take you only 3 minutes in 8 steps!

------------------------------------------------------------------
1. Choose Component and then New Component to start....


------------------------------------------------------------------
2. The New Component dialog appears, in which you need to choose a few items.

Note that the ClassName and the Unit File Name need to be different, for example if the ClassName is TButtonHell, your unit could be named ButtonHell.pas. It is standard to begin your Classname with the character "T" but not required.


------------------------------------------------------------------
3. Next choose the Install button and the Install dialog will appear


------------------------------------------------------------------
4. Choose the default option, or click the second tab and install to a new package

Choose a unique name for your package, you could include the version like in this case ButtonHell7.dpk


------------------------------------------------------------------
5. Click ok, and delphi will ask for a confirmation using the confirmation dialog, click Yes

The resulting Unit will look like the one below:


unit ButtonHell;

interface

uses

  SysUtils, Classes, Controls, StdCtrls;

type

  TButtonHell = class(TButton)

  private

    { Private declarations }

  protected

    { Protected declarations }

  public

    { Public declarations }

  published

    { Published declarations }

  end;



     procedure Register;

implementation

     procedure Register;

       begin

          RegisterComponents('Fdehell', [TButtonHell]);

        end;



end.


------------------------------------------------------------------
6. Make the following changes in between {==Start...End==}


unit ButtonHell;

interface

uses

  SysUtils, Classes, Controls, StdCtrls;

type

  TButtonHell = class(TButton)

  private

    { Private declarations }

  protected

    { Protected declarations }

  public

{==Start
constructor Create(AOwner: TComponent); override;
End==}

  published

    { Published declarations }

  end;

     procedure Register;

implementation

      
{==Start
constructor TButtonHell.Create(AOwner: TComponent);

       begin

         inherited Create(AOwner);

            

    end;    
End==}


     procedure Register;

       begin

          RegisterComponents('Fdehell', [TButtonHell]);

      end;



end.


------------------------------------------------------------------
7. Now, this was not that difficult, if you keep reading, you will find that the rest is not that difficult either! In fact one more step and you have  created your own component! Let's change some of the values to suit our needs, say we want the Tbutton, to show it's Hint [visible when hovering over it] by default, here is how we can do that:

Publish the property that you want to change by default, in the Published Section:


published

    property  Showhint default True;



Then declare the property in the constructor



constructor TButtonHell.Create(AOwner: TComponent);

   begin

    inherited Create(AOwner);

       ShowHint := True;

  end;


------------------------------------------------------------------
8. Save and compile this, you have just created your own Tbutton, that has your default! For your reference here follows the completed tutorial. One more example is included in the zipfile, note that you have to create it using the Delphi interface, meaning that copy and pasting the whole code will not work, since Delphi creates several files more as you use the above descripbed way to create components.



unit ButtonHell;

interface

uses

  SysUtils, Classes, Controls, StdCtrls;


type

  TButtonHell = class(TButton)

  private

    { Private declarations }

  protected

    { Protected declarations }

  public

      constructor Create(AOwner: TComponent); override;

  published

       property  Showhint default True;

  end;

procedure Register;

implementation

constructor TButtonHell.Create(AOwner: TComponent);

   begin

    inherited Create(AOwner);

       ShowHint := True;

  end;


procedure Register;

begin

  RegisterComponents('Fdehell', [TButtonHell]);

end;



end.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
A. B. Talal
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)