Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
494 Users Online NOW
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



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






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 create a DataBaseName Property ?Go to Christophe Geers's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
How to create a component with a DataBaseName property.
Product:
Delphi 3.x (or higher)
Category:
DB-General
Skill Level:
Scoring:
Last Update:
09/07/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet DataBaseName property RegisterPropertyEditor
Times Scored:
2
Visits:
3305
Uploader: Christophe Geers
Company: ANDROME nv
Reference: N/A
 
Question/Problem/Abstract:
The following example shows how to create a component with a DataBaseName property like the DataBaseName property of TQuery. The purpose of this property is to list all the available databases so that the user of the component can just select the required database.
Answer:



Please note that for this example I have put all the code in one unit, but if you want to make such a component you must make sure that you place all the design time code in a seperate unit.

How is this done:

- Remove the DesignIntf, DesignEditors units from the uses clause.
- Create a new unit (xxxxDesignTime).
- Move the Register procedure in to the new unit too.
- All the none design code can stay in the other unit.
- Make a package.
- Add both units to the package.
- Install the package.

The reason for this is that it is and has been illegal to distribute the designtime code. Borland are now enforcing it by making key units only available in the IDE via packages.

unit TestDataBaseNameProperty;

interface

uses
  Windows, Messages, SysUtils, Classes, DBTables, DesignIntf, DesignEditors;

type

  TDBStringProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValueList(List: TStrings); virtual; abstract;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  TDatabaseNameProperty = class(TDBStringProperty)
  public
    procedure GetValueList(List: TStrings); override;
  end;
  
  TTestDataBaseNameProperty = class(TComponent)
  private
    { Private declarations }
    FDataBaseName : String; //Stores the name of the selected database.
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property DataBaseName: String read FDataBaseName write FDataBaseName;
  end;

procedure Register;

implementation

procedure Register;
begin
  //Registry the property editor for the database names.
  RegisterPropertyEditor(TypeInfo(String),TLanguageChanger,
  'DataBaseName',TDatabaseNameProperty);
  RegisterComponents('Self-made Components', [TLanguageChanger]);
end;

{ TTestDataBaseNameProperty }

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

destructor TLanguageChanger.Destroy;
begin
  inherited Destroy;
end;

procedure TTestDataBaseNameProperty.setFormID(Value: Integer);
begin
  FFormID := Value;
end;

procedure TTestDataBaseNameProperty.setLanguageID(value: Integer);
begin
  FLanguageID := Value;
end;

{ TDBStringProperty }

function TDBStringProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList, paSortList, paMultiSelect];
end;

procedure TDBStringProperty.GetValues(Proc: TGetStrProc);
var
  I: Integer;
  Values: TStringList;
begin
  Values := TStringList.Create;
  try
    GetValueList(Values);
    for I := 0 to Values.Count - 1 do Proc(Values[I]);
  finally
    Values.Free;
  end;
end;

{ TDatabaseNameProperty }

procedure TDatabaseNameProperty.GetValueList(List: TStrings);
begin
  Session.GetDatabaseNames(List);
end;

end.

Tested with Delphi 6 Professional on Windows 2000. Be sure to include ALL the UNITS. (Thanks to hvassbotn for the help).





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
Peganza
 
   














 







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