uses DB; 用法: var Tb:TBookMark; begin with Query1 do begin Tb:=GetBookMark; Close; Open; Try GotoBookMark(Tb); except Last; end; end; end;也可以用locate
记下上次的那条记录的id 1 ADOQuery1.MoveBy(id); 2 定义 type TMyDBGrid=class(TDBGrid); 3 procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin with TMyDBGrid(Sender) do begin if DataLink.ActiveRecord=Row-1 then begin Canvas.Font.Color:=clWhite; Canvas.Brush.Color:=$00800040; end else begin Canvas.Brush.Color:=clBtnFace; Canvas.Font.Color:=Clred; end; DefaultDrawColumnCell(Rect,DataCol,Column,State); end; end;
DB;
用法:
var Tb:TBookMark;
begin
with Query1 do begin
Tb:=GetBookMark;
Close; Open;
Try
GotoBookMark(Tb);
except
Last;
end;
end;
end;也可以用locate
2 定义 type
TMyDBGrid=class(TDBGrid);
3 procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with TMyDBGrid(Sender) do
begin
if DataLink.ActiveRecord=Row-1 then
begin
Canvas.Font.Color:=clWhite;
Canvas.Brush.Color:=$00800040;
end
else
begin
Canvas.Brush.Color:=clBtnFace;
Canvas.Font.Color:=Clred;
end;
DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
end;
或者用DBGrid2.DataSource.Dataset替换DBGrid2
用DBGrid2.DataSource.Dataset替换Query1