Advertisement
Guest User

draw cell in TIB_Grid

a guest
Mar 2nd, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.06 KB | None | 0 0
  1. {
  2. var
  3.   gr_RezCli: TIB_Grid;
  4.  
  5. gr_RezCli.OnDrawCell := gr_RezCliDrawCell;
  6. }
  7.  
  8. // draw icon in cell if field REZ_MEMO is not empty
  9. procedure TW_Rez.gr_RezCliDrawCell( Sender: TObject; ACol, ARow: Integer;
  10.                                     Rect: TRect; State: TGridDrawState );
  11. var
  12.   sFieldName : String;
  13.   bmp        : TBitmap;
  14.   iLeftMargin: Integer;
  15.   iTopMargin : Integer;
  16.   DrawRect   : TRect;
  17. begin
  18.   if (gdFixed in State) or
  19.      not Assigned(gr_RezCli) or
  20.      not Assigned(gr_RezCli.GridFields[ACol-1]) or
  21.      not Assigned(W_DM_Rez) or
  22.      not Assigned(W_DM_Rez.D_Rez_Cli) or
  23.      not Assigned(W_DM_Rez.Q_Rez_Cli) or
  24.      //not W_DM_Rez.Q_Rez_Cli.Prepared or
  25.      not W_DM_Rez.Q_Rez_Cli.Active or
  26.      W_DM_Rez.Q_Rez_Cli.FieldByName('ID_REZEPT').IsNull or
  27.      (W_DM_Rez.Q_Rez_Cli.RecordCount < 1) then
  28.   begin
  29.     exit;
  30.   end;
  31.  
  32.   try
  33.     W_DM_Rez.Q_Rez_Cli.BufferRowNum := gr_RezCli.DataRow[ARow];
  34.     sFieldName := UpperCase( gr_RezCli.GridFields[ACol-1].FieldName );
  35.  
  36.     if (sFieldName = 'REZ_MEMO') and
  37.        not W_DM_Rez.Q_Rez_Cli.BufferFieldByName('REZ_MEMO').IsNull then
  38.     begin
  39.       // inflate rect by line width
  40.       Rect.Left   := Rect.Left + 1;
  41.       Rect.Right  := Rect.Right - 1;
  42.       Rect.Top    := Rect.Top + 1;
  43.       Rect.Bottom := Rect.Bottom - 1;
  44.       // fill background
  45.       gr_RezCli.Canvas.FillRect( Rect );
  46.       // icon
  47.       bmp := TBitmap.Create;
  48.       try
  49.         // load bitmap from resource
  50.         Bingo_LoadBitmapByIdent( imgDateInfo, bmp );
  51.         // center icon
  52.         iLeftMargin := ((Rect.Right-Rect.Left) - bmp.Width) div 2;
  53.         iTopMargin  := ((Rect.Bottom-Rect.Top) - bmp.Height) div 2;
  54.         DrawRect := Bounds( Rect.Left+iLeftMargin, Rect.Top+iTopMargin, bmp.Width, bmp.Height );
  55.         // draw icon
  56.         gr_RezCli.Canvas.BrushCopy( DrawRect, bmp, Bounds(0, 0, bmp.Width, bmp.Height),
  57.                                     bmp.TransparentColor );
  58.       finally
  59.         bmp.Free;
  60.       end;
  61.     end;
  62.   except
  63.     on E: Exception do begin
  64.       // log stuff
  65.     end;
  66.   end;
  67. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement