Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Delphi Components Writing > Convert to Data...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 131 of 155
Post > Topic >>

Convert to Data Aware?

by "ielite" <ielite@[EMAIL PROTECTED] > May 1, 2005 at 04:23 PM

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, Cl*****, 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.
 




 3 Posts in Topic:
Convert to Data Aware?
"ielite" <ie  2005-05-01 16:23:47 
Re: Convert to Data Aware?
"Bruce Roberts"  2005-05-02 10:40:22 
Re: Convert to Data Aware?
"ielite" <ie  2005-05-02 11:59:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 18:30:32 CDT 2008.