UNIT TESTDBG;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGRIDS, DB, ADODB, STDCTRLS, TYPES;
type TForm1 = class (TForm) DBG: TDBGrid; ADOConnection1: TADOConnection; ADOTable1: TADOTable; DataSource1: TDataSource; procedure DBGDrawColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); procedure DBGKeyPress (Sender: TOBJECT; VAR Key: char); Procedure formcreate (sender: TOBJECT); private {private declarations} end;
Var Form1: TFORM1; Implementation
{$ R * .dfm} type myRect = array [0..200] of tpoint; var me: myRect; // Record points I: Integer; cpoint: tpoint; // Current point in the upper left corner of the cell
procedure TForm1.DBGDrawColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var J: integer; begin if (gdFocused in State) {or (gdSelected in State) or (gdFixed in State)} The next statement below is the left upper corner coordinate of the current active cell} cpoint.x: = Rect.top; cpoint.y: = Rect.top; end; for j: = 0 To i do begin if (Rect.top = Me [J) and (Rect.Left = ME [J] .x) THEN BEGIN / / Decision whether the cell exists in records of the modified array! DBG.canvas.brush .Color: = CLRED; DBG.DEFAULTDRED;
Procedure tForm1.dbgKeyPress (Sender: Tobject; var key: char); {Due to the better record point, if you modify it, only one button is pressed, will not trigger this statement! Because of the first execution of this statement When the data has not been modified or inserted. I only tested the modified state, the added state did not test it! In this state: for j: = 0 to i do begin // Determine if the grid has recorded IF (ME [J] .x = cpoint.x) and (me [j] .y = cpoint.y) THEN EXIT ; // If you don't record it! ME [i] .x: = cpoint.x; me [i] .y: = cpoint.y; i: = i 1; end; end; procedure TFORM1.FORMCREATE (Sender: TOBJECT); begin i: = 0; // Initialization of the starting point END;
End.
I just made a modified test, it is successful, so few code is definitely unable to meet everyone's higher demand, here is only the most basic function, so that everyone understands, what is the higher requirement, of course, according to each People's needs, play some digital games! You can modify it into safer and more useful!
Thank you for your support!
Original works are struggling, reprint, please explain the article: http://blog.9cbs.net/kfarvid or http://www.cnblogs.com/kfarvid/