Forum > Win32/64

Why define NewCols in Grids.pas

(1/1)

kinlion:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$define NewCols}and the function:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TGridColumns.GetVisibleCount: Integer;{$ifNdef newcols}var  i: Integer;{$endif}begin  {$ifdef newcols}  result := Count;  {$else}  result := 0;  for i:=0 to Count-1 do    if Items[i].Visible then      inc(result);  {$endif}end; 
The definition makes the function igoring Coulmn's Visible property.
Why?

kinlion:
OK. I understand it now after reading  this function:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TGridColumn.GetWidth: Integer;var  tmpGrid: TCustomGrid;begin  {$ifdef newcols}  if not Visible then    exit(0);  {$endif}  if FWidth=nil then    result := GetDefaultWidth  else    result := FWidth^;  if (result<0) then  begin    tmpGrid := Grid;    if tmpGrid<>nil then      result := tmpGrid.DefaultColWidth;  end;end; 
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.

Navigation

[0] Message Index

Go to full version