假设你那个逻辑字段叫select(我用的ADO,BDE也一样)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, Grids, DBGrids, ADODB;
type
TForm1 = class(TForm)
ADOTable1: TADOTable;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure SetDisplayText(Sender: TField; var Text: String; DisplayText: Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
adotable1.Open;
end;
procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
if column.FieldName = 'select' then
begin
adotable1.Edit;
adotable1.FieldByName('select').AsBoolean :=
not adotable1.FieldByName('select').AsBoolean;
adotable1.Post;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
adotable1.Fields[1].OnGetText := SetDisplayText;
end;
procedure TForm1.SetDisplayText(Sender: TField; var Text: String; DisplayText: Boolean);
begin
if Sender.FieldName = 'select' then
if Sender.AsBoolean then
Text := '√'
else
Text := '×';
DisplayText := True;
end;
end.