您可以覆盖 CanEditModify 函数并添加您希望的条件。这可以通过添加新事件或仅通过 interposerclass 创建新组件来完成。
unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids;
type
TDBGrid=Class(DBGrids.TDBgrid)
function CanEditModify: Boolean; override;
Property Col; // make property col visible
End;
TForm6 = class(TForm)
DBGrid1: TDBGrid;
ADOConnection1: TADOConnection;
ADODataSet1: TADODataSet;
DataSource1: TDataSource;
ADODataSet1Componame: TStringField;
ADODataSet1TrackTitle: TStringField;
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form6: TForm6;
implementation
{$R *.dfm}
{ TDBGrid }
function TDBGrid.CanEditModify: Boolean;
var
f:TField;
c:Integer;
begin
Result := inherited CanEditModify;
c := Col;
if dgIndicator in Options then dec(c);
F := Columns[c].Field;
if Assigned(F) then
begin // here just an example condition
if (f.FieldName='TrackTitle') then
if Pos('aa',F.AsString)>0 then Result := False;
// you also can access the dataset via
// if f.DataSet.FieldByName('xy').SomeCondition then ....
end;
end;
end.