whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

35 Visitors Online


 
...get the content of a TStringgrid/ TDrawGrid as a string?
Autor: Thomas Mueller
Homepage: http://www.s2h.cx
[ Print tip ]  

Tip Rating (4):  
     


{
 This copies the contents of a TstringGrid/TDrawGrid (only Text!!) into a string.
 Tabs are inserted between the columns, CR+LF between rows.
}

use
  Grids;

{...}

{ we need this Cracker Class because the Col/RowCount property
  is not public in TCustomGrid }
type
  
TGridHack = class(TCustomGrid);

function GetstringGridText(_Grid: TCustomGrid): string;
var
  
Grid: TGridHack;
  Row, Col: Integer;
  s: string;
begin
  
// Cast the paramter to a TGridHack, so we can access protected properties
  
Grid   := TGridHack(_Grid);
  Result := '';
  // for all rows, then for all columns
  
for Row := 0 to Grid.RowCount - 1 do
  begin
    for 
Col := 0 to Grid.ColCount - 1 do
    begin
      
// the first column does not need the tab
      
if Col > 0 then
        
Result := Result + #9;
      Result := Result + Grid.GetEditText(Col, Row);
    end;
    Result := Result + #13#10;
  end;
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners