Thread View: borland.public.delphi.database
1 messages
1 total messages
Started by twistedvoid
Thu, 06 Mar 2008 03:34
DB Aware button on a CtrlGrid
Author: twistedvoid
Date: Thu, 06 Mar 2008 03:34
Date: Thu, 06 Mar 2008 03:34
107 lines
3782 bytes
3782 bytes
Ok, I'm in need of a db aware button to place on a control grid. All
it has to do is copy the field info to the clipboard when clicked.
Thus far, I've only found some code written several years ago on
about.com. It works with one big exception. The button caption isn't
updated with the proper field data when a new panel in the ctrlgrid is
drawn. It does update the caption when you click on the button, but
then all of the button captions get updated. I've played with this
and am clueless as to whether it can be made to update on a ctrlgrid.
Can someone point me in the right direction?
unit DBButton;
interface
uses
DB, DBCtrls, SysUtils, Classes,
Controls, StdCtrls;
type
TDBButton = class(TButton)
private
FDataLink : TFieldDataLink;
function GetDataField: string;
function GetDataSource: TDataSource;
function GetField: TField;
procedure SetDataField(const Value: string);
procedure SetDataSource(const Value: TDataSource);
protected
procedure DataChange(Sender : TObject);
public
constructor Create(AOwner : TComponent);
override;
destructor Destroy; override;
property Field : TField read GetField;
published
property DataSource : TDataSource
read GetDataSource
write SetDataSource;
property DataField : string
read GetDataField
write SetDataField;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('delphi.about.com',
[TDBButton]);
end;
constructor TDBButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDataLink := TFieldDataLink.Create;
FDataLink.Control := self;
FDataLink.OnDataChange := DataChange;
end;
destructor TDBButton.Destroy;
begin
FDataLink.Free;
FDataLink := nil;
inherited;
end;
procedure TDBButton.DataChange(
Sender: TObject);
begin
Caption := FDataLink.Field.AsString;
Enabled := NOT FDataLink.Field.IsNull;
end;
function TDBButton.GetField: TField;
begin
result := FDataLink.Field;
end;
function TDBButton.GetDataField: string;
begin
result := FDataLink.FieldName;
end;
procedure TDBButton.SetDataField(
const Value: string);
begin
FDataLink.FieldName := value;
end;
function TDBButton.GetDataSource: TDataSource;
begin
result := FDataLink.DataSource;
end;
procedure TDBButton.SetDataSource(
const Value: TDataSource);
begin
FDataLink.DataSource := Value;
end;
end. //DBButton
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads