BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Making a Component DataAware

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing
View previous topic :: View next topic  
Author Message
ielite
Guest





PostPosted: Sun May 01, 2005 8:22 pm    Post subject: Making a Component DataAware Reply with quote



Is their anyone out there that can help me convert this into a dataaware
version:


I have a database with a table (consoles) with the following fields:

Id: Integer
Name: String
IMage: TBitmap


The Custom Panel has a collection (TConsoles) of Items (TConsole)


I guess the component should have a Datasource Property
and each TConsole should have a Field Property


A DataAware browing component is fine, but one that allows for editing would
be nice!

Shane


unit XConsoles;

interface

uses
SysUtils, Classes, Controls, ExtCtrls, XPanel, Graphics;

type

TConsole = class(TCollectionItem)
private
fId: Integer;
fName : String;
fImage: TBitmap;
procedure SetId(Value: Integer);
procedure SetName(Value: String);
procedure SetImage(Value: TBitmap);
protected
function GetDisplayName : String; override;
public
procedure Assign(Source: TPersistent); override;
constructor Create(Collection: TCollection);override;
destructor Destroy;override;
published
property Id: Integer read fId write SetId;
property Name : String read fName write SetName;
property Image: TBitmap read fImage write SetImage;
end;

TConsoles = class(TCollection)
private
fOwner : TComponent;
protected
function GetOwner : TPersistent; override;
function GetItem(Index: Integer): TConsole;
procedure SetItem(Index: Integer; Value: TConsole);
procedure Update(Item: TConsole);
public
constructor Create(AOwner : TComponent);
function Add : TConsole;
function Insert(Index: Integer): TConsole;
property Items[Index: Integer]: TConsole read GetItem write SetItem;
end;

TXConsoles = class(TXPanel)
private
{ Private declarations }
fConsoles : TConsoles;
procedure SetConsoles(const Value: TConsoles);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property Consoles : TConsoles read fConsoles write SetConsoles;
end;

procedure Register;

implementation

procedure TConsole.SetId(Value: Integer);
begin
if fId <> Value then fId:= Value;
end;

procedure TConsole.SetName(Value: String);
begin
if fName <> Value then fName:= Value;
end;

procedure TConsole.SetImage(Value: TBitmap);
begin
fImage.Assign(Value);
end;

procedure TConsole.Assign(Source: TPersistent);
begin
if Source is TConsole then
begin
Id:= TConsole(Source).Id;
Name := TConsole(Source).Name;
Image.Assign(TConsole(Source).Image);
end
else
inherited; //raises an exception
end;

function TConsole.GetDisplayName: String;
begin
Result := Format('Item %d',[Index]);
end;

constructor TConsole.Create(Collection: TCollection);
begin
inherited Create(Collection);
fImage:= TBitmap.Create;
end;

destructor TConsole.Destroy;
begin
fImage.Free;
inherited Destroy;
end;


constructor TConsoles.Create(AOwner: TComponent);
begin
inherited Create(TConsole);
fOwner := AOwner;
end;

function TConsoles.Add: TConsole;
begin
Result := TConsole(inherited Add);
end;

function TConsoles.GetItem(Index: Integer): TConsole;
begin
Result := TConsole(inherited GetItem(Index));
end;

function TConsoles.GetOwner: TPersistent;
begin
Result := FOwner;
end;

function TConsoles.Insert(Index: Integer): TConsole;
begin
Result := TConsole(inherited Insert(Index));
end;

procedure TConsoles.SetItem(Index: Integer; Value: TConsole);
begin
inherited SetItem(Index, Value);
end;

procedure TConsoles.Update(Item: TConsole);
begin
inherited Update(Item);
end;


constructor TXConsoles.Create(AOwner: TComponent);
begin
inherited;
fConsoles := TConsoles.Create(Self);
end;

destructor TXConsoles.Destroy;
begin
fConsoles.Free;
inherited;
end;

procedure TXConsoles.SetConsoles(const Value: TConsoles);
begin
fConsoles.Assign(Value);
end;

procedure Register;
begin
RegisterComponents('Panels', [TXConsoles]);
end;

end.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.