TFieldDataLink 就可以了
==========================
unit DBBitBtn1;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Buttons,
DBCtrls, DB;
type
TDBBitBtn1 = class(TBitBtn)
private
{ Private declarations}
FDataLink: TFieldDataLink;
function GetDataField: string;
procedure SetDataField(const Value: string);
function GetDataSource: TDataSource;
procedure SetDataSource(const Value: TDataSource);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property DataField: string read GetDataField write SetDataField;
property DataSource: TDataSource read GetDataSource write SetDataSource;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TDBBitBtn1]);
end;
{ TDBBitBtn1 }
constructor TDBBitBtn1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
end;
destructor TDBBitBtn1.Destroy;
begin
FDataLink.Free;
FDataLink := nil;
inherited Destroy;
end;
function TDBBitBtn1.GetDataField: string;
begin
Result := FDataLink.FieldName;
end;
function TDBBitBtn1.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure TDBBitBtn1.SetDataField(const Value: string);
begin
FDataLink.FieldName := Value;
end;
procedure TDBBitBtn1.SetDataSource(const Value: TDataSource);
begin
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
FDataLink.DataSource := Value;
if Value <> nil then Value.FreeNotification(Self);
end;
end.