好的,谢谢大家~如果改好了,晚上就可以通宵看世界杯了!~~
unit scDBButtonEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, dxCntner, dxEditor,
dxExEdtr, dxEdLib, dxDBELib, ADODB, DB;
type
TscDBButtonEdit = class(TdxDBButtonEdit)
private
{ Private declarations }
FSQL: String;
FTitleCaption: string;
FOnButtonClick: TNotifyEvent;
procedure btnClick(Sender: TObject);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
//property OnButtonClick: TNotifyEvent read FOnButtonClick write FOnButtonClick;
property SQL: String read FSQL write FSQL;
property TitleCaption: string read FTitleCaption write FTitleCaption;
end;
procedure Register;
implementation
uses scDBGridSelectItemDlg;
procedure Register;
begin
RegisterComponents('SCVCL', [TscDBButtonEdit]);
end;
{ TscDBButtonEdit }
procedure TscDBButtonEdit.BtnClick(Sender: TObject);
var
DBGridSelectItemDlg: TscDBGridSelectItemDlg;
begin
if Assigned(FOnButtonClick) then
FOnButtonClick(Self);
if (DataSource = nil) or (DataField = '') then
raise Exception.Create('未设置数据连接属性!');
if not(DataSource.DataSet.State in [dsEdit, dsInsert]) then
Exit;
try
DBGridSelectItemDlg := TscDBGridSelectItemDlg.Create(Self);
with DBGridSelectItemDlg do
begin
qry.Connection := TADOQuery(DataSource.DataSet).Connection;
FormSQL := FSQL;
FormTitleCaption := FTitleCaption;
end;
if DBGridSelectItemDlg.ShowModal = mrOK then
DataSource.DataSet.FieldByName(DataField).AsString := DBGridSelectItemDlg.qry.Fields[0].AsString;
finally
DBGridSelectItemDlg.Free;
end;
end;
constructor TscDBButtonEdit.Create(AOwner: TComponent);
begin
inherited;
// OnButtonClick := btnClick;
end;
end.