Recent

Author Topic: Why define NewCols in Grids.pas  (Read 3018 times)

kinlion

  • Jr. Member
  • **
  • Posts: 82
  • I Love Lazarus
Why define NewCols in Grids.pas
« on: November 30, 2018, 01:19:09 pm »
When using TStringGrid, I hide some columns in  the Object Inspector. Then I want to get the count of visible columns by calling StringGrid.Columns.VisibleColCount, but the result is wrong because it counts the invivible columns.
Deep into the grids.pas, I found there is a defeine at the head of the file:
Code: Pascal  [Select][+][-]
  1. {$define NewCols}
and the function:
Code: Pascal  [Select][+][-]
  1. function TGridColumns.GetVisibleCount: Integer;
  2. {$ifNdef newcols}
  3. var
  4.   i: Integer;
  5. {$endif}
  6. begin
  7.   {$ifdef newcols}
  8.   result := Count;
  9.   {$else}
  10.   result := 0;
  11.   for i:=0 to Count-1 do
  12.     if Items[i].Visible then
  13.       inc(result);
  14.   {$endif}
  15. end;
  16.  

The definition makes the function igoring Coulmn's Visible property.
Why?

kinlion

  • Jr. Member
  • **
  • Posts: 82
  • I Love Lazarus
Re: Why define NewCols in Grids.pas
« Reply #1 on: November 30, 2018, 01:26:06 pm »
OK. I understand it now after reading  this function:
Code: Pascal  [Select][+][-]
  1. function TGridColumn.GetWidth: Integer;
  2. var
  3.   tmpGrid: TCustomGrid;
  4. begin
  5.   {$ifdef newcols}
  6.   if not Visible then
  7.     exit(0);
  8.   {$endif}
  9.   if FWidth=nil then
  10.     result := GetDefaultWidth
  11.   else
  12.     result := FWidth^;
  13.   if (result<0) then
  14.   begin
  15.     tmpGrid := Grid;
  16.     if tmpGrid<>nil then
  17.       result := tmpGrid.DefaultColWidth;
  18.   end;
  19. end;
  20.  

To define NewCols means to treat the unvisible columns as a zero-widthed column instead of removing it from columns logically. Maybe for speeding up code.

 

TinyPortal © 2005-2018