Article View: borland.public.delphi.database
Article #175DB Aware button on a CtrlGrid
From: 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
Technical Details
Message-ID:
<9c8a5308-0899-4cc2-844e-b350dc27d8d1@u72g2000hsf.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!u72g2000hsf.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 115d96,7e2a2737fbb1ec7b,start X-Google-Attributes: gid115d96,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!u72g2000hsf.googlegroups.com!not-for-mail From: twistedvoid@gmail.com Newsgroups: borland.public.delphi.database Subject: DB Aware button on a CtrlGrid Date: Wed, 5 Mar 2008 19:34:56 -0800 (PST) Organization: http://groups.google.com Lines: 107 Message-ID: <9c8a5308-0899-4cc2-844e-b350dc27d8d1@u72g2000hsf.googlegroups.com> NNTP-Posting-Host: 75.210.96.92 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1204774497 5652 127.0.0.1 (6 Mar 2008 03:34:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 6 Mar 2008 03:34:57 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u72g2000hsf.googlegroups.com; posting-host=75.210.96.92; posting-account=e6xzeQoAAAAj03yy2LIR_WT7JEbTyzVr User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506),gzip(gfe),gzip(gfe)