L
lishding
Unregistered / Unconfirmed
GUEST, unregistred user!
我想在运行时,动态创建一DBGrid组件显示数据供选择,写了以下函数,
但在为 DBGrid 的 OnDblClick 赋值出错!!!
代码如下:
function ShowGrid(sender: TObject):string;
var ListGrid:TDBGrid;
ListDataSet:TADOQuery;
ListDataSource:TDataSource ;
// 在所创建的ListGrid的 OnDblClick 事件中 释放所创建的组件
Procedure CloseDBGrod(Sernder:TObject);
begin
// ListGrid.OnDblClick((Sender as TWinControl));
ListGrid.Free;
ListDataSet.Close;
ListDataSet.Free;
ListDataSource.Free;
end;
begin
// 创建数据集
ListDataSet :=TADOQuery.Create( (Sender as TWinControl).Parent);
ListDataSet.Connection:=Form1.ADOConnection1; //**
ListDataSet.SQL.Clear;
ListDataSet.SQL.Append('select * from A02 '); //**
ListDataSet.Open;
// 创建数据源
ListDataSource:=TDataSource.Create((Sender as TWinControl).Parent);
ListDataSource.DataSet:=ListDataSet;
// 创建DBGrid
ListGrid:=TDBGrid.Create((Sender as TWinControl).Parent);
ListGrid.Visible:=false;
ListGrid.Options:=ListGrid.Options+[dgRowSelect];
ListGrid.ReadOnly:=true;
ListGrid.Font.Name:='宋体';
ListGrid.Font.Size:=10;
ListGrid.Color:=clInfoBk;
ListGrid.TitleFont:=ListGrid.Font;
ListGrid.DataSource:=ListDataSource;
ListGrid.Parent:=(Sender as TWinControl).Parent;
ListGrid.Left:=(Sender as TWinControl).left;
ListGrid.Top:=(Sender as TWinControl).top+(Sender as TWinControl).Height-1;
ListGrid.Width:=260;
ListGrid.Height:=180;
ListGrid.Columns.RestoreDefaults;
ListGrid.Visible:=true;
ListGrid.SetFocus;
ListGrid.OnDblClick:=CloseDBGrod;
{ 上面这行出错: Incompatible Types:'method pointer and regular procedure' }
但在为 DBGrid 的 OnDblClick 赋值出错!!!
代码如下:
function ShowGrid(sender: TObject):string;
var ListGrid:TDBGrid;
ListDataSet:TADOQuery;
ListDataSource:TDataSource ;
// 在所创建的ListGrid的 OnDblClick 事件中 释放所创建的组件
Procedure CloseDBGrod(Sernder:TObject);
begin
// ListGrid.OnDblClick((Sender as TWinControl));
ListGrid.Free;
ListDataSet.Close;
ListDataSet.Free;
ListDataSource.Free;
end;
begin
// 创建数据集
ListDataSet :=TADOQuery.Create( (Sender as TWinControl).Parent);
ListDataSet.Connection:=Form1.ADOConnection1; //**
ListDataSet.SQL.Clear;
ListDataSet.SQL.Append('select * from A02 '); //**
ListDataSet.Open;
// 创建数据源
ListDataSource:=TDataSource.Create((Sender as TWinControl).Parent);
ListDataSource.DataSet:=ListDataSet;
// 创建DBGrid
ListGrid:=TDBGrid.Create((Sender as TWinControl).Parent);
ListGrid.Visible:=false;
ListGrid.Options:=ListGrid.Options+[dgRowSelect];
ListGrid.ReadOnly:=true;
ListGrid.Font.Name:='宋体';
ListGrid.Font.Size:=10;
ListGrid.Color:=clInfoBk;
ListGrid.TitleFont:=ListGrid.Font;
ListGrid.DataSource:=ListDataSource;
ListGrid.Parent:=(Sender as TWinControl).Parent;
ListGrid.Left:=(Sender as TWinControl).left;
ListGrid.Top:=(Sender as TWinControl).top+(Sender as TWinControl).Height-1;
ListGrid.Width:=260;
ListGrid.Height:=180;
ListGrid.Columns.RestoreDefaults;
ListGrid.Visible:=true;
ListGrid.SetFocus;
ListGrid.OnDblClick:=CloseDBGrod;
{ 上面这行出错: Incompatible Types:'method pointer and regular procedure' }