Click here to Skip to main content
12,065,756 members (27,614 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Delphi
I am trying to add a checkbox to a DBGrid for displaying data. Here is an extract from the code I have trouble with. Not sure what the problem is or how to describe it either. Read the comment in the code for the problem explanation please:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
  
const IsChecked : array[Boolean] of Integer = 
      (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  DrawState: Integer;
  DrawRect: TRect;
begin
  if (gdFocused in State) then
  begin
    if (Column.Field.FieldName = DBCheckBox1.DataField) then
    begin
     DBCheckBox1.Left := Rect.Left + DBGrid1.Left + 2;
     DBCheckBox1.Top := Rect.Top + DBGrid1.top + 2;
     DBCheckBox1.Width := Rect.Right - Rect.Left;
     DBCheckBox1.Height := Rect.Bottom - Rect.Top;
 
     DBCheckBox1.Visible := True;
    end
  end
  else
  begin
    if (Column.Field.FieldName = DBCheckBox1.DataField) then
    begin
      DrawRect:=Rect;
      InflateRect(DrawRect,-1,-1);
 
      DrawState := ISChecked[Column.Field.AsBoolean]; //Here is the problem... I use Embarcadero RAD Studio XE2 and am new to Delphi. Not sure if this line of code is only relevent to Delphi7. Could more light on this perhaps be shed? Maybe direct me to an appropriate source so I can use this code in my program? In my  RAD studio, 'ISChecked' is underlined in RED and is said to be an undeclared identifier... What am I doing wrong? Am I missing something?

      DBGrid1.Canvas.FillRect(Rect);
      DrawFrameControl(DBGrid1.Canvas.Handle, DrawRect, DFC_BUTTON, DrawState);
    end;
  end; 
end;

Here is the link to the site I obtained this code from:

http://delphi.about.com/od/usedbvcl/l/aa082003a.htm[^]

Any suggestions would be greatly appreciated!
Thanx
Posted 2-Jul-12 8:21am
Comments
Wes Aday 2-Jul-12 14:24pm
   
I am not at all and expert in Delphi or Pascal. But ISChecked would seem to me to be unusual. Try IsChecked instead and see what happens. If not, then good luck!
   
When I worked with Delphi and all the time before, Pascal was case-insensitive...
--SA
Wes Aday 2-Jul-12 14:57pm
   
Ah, thanks. Now I know. Thought it was worth a shot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160207.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100