Board index » delphi » TStringGrid: Cell property

TStringGrid: Cell property

 I am manually reading a text database file to a TStringGrid using the Cells
property (i.e. TStringGrid.Cells[1,3] := 'Text').  I have found that Delphi
1.0 is limiting me to about 32,000 rows.  This is because the values of ARow
and ACol (the values passed to the Cells property) limit me to an integer
value.  The TStringGrid properties ColCount and RowCount are both LongInt.
There seems to be an inconsistency here.  In the meantime, does anybody know
of a way to write to rows beyond the +/-32,000?  Or, does anybody know of an
alternate TStringGrid component which will allow me to access rows beyond
the 8-bit integer limit that TStringGrid imposes?  (It needs to be
compatible with Delphi 1.0 and preferrably freeware---I know, I'm cheap...)

Thanks a lot.

Robert C. Ingebretsen

 

Re:TStringGrid: Cell property


Quote
>  I am manually reading a text database file to a TStringGrid using the
Cells
> property (i.e. TStringGrid.Cells[1,3] := 'Text').  I have found that
Delphi
> 1.0 is limiting me to about 32,000 rows.  This is because the values of
ARow
> and ACol (the values passed to the Cells property) limit me to an integer
> value.  The TStringGrid properties ColCount and RowCount are both
LongInt.
> There seems to be an inconsistency here.  In the meantime, does anybody
know
> of a way to write to rows beyond the +/-32,000?  Or, does anybody know of
an
> alternate TStringGrid component which will allow me to access rows beyond
> the 8-bit integer limit that TStringGrid imposes?  

hum, you mean 16-bit integer

Quote
> Robert C. Ingebretsen

It would surely be possible, why not, but
1. think about memory usage:
each cell uses at least 12 bytes+string buffer, so if a 1K record is spread
accross 10 cells it would use 1148 bytes * 32000 records is over 33 MBYTES,
however re-allocations also take space.
Do the following test: create two string lists (max 16k items each) and
fill them with full string(255). Calculated usage would be 8MB, actual will
be much more.
2. think about load time
3. think about browsing grid with over 32000 rows
.....

Maybe you should re-think the scope.
Just an idea.
--
-------------------------
Regards,
Robert

MailTo:robert.ce...@eunet.si

Re:TStringGrid: Cell property


In article <5v7nbr$c6...@news.aros.net>, "Robert C. Ingebretsen"
<r.c.ingebret...@m.cc.utah.edu> writes

Quote

> I am manually reading a text database file to a TStringGrid using the Cells
>property (i.e. TStringGrid.Cells[1,3] := 'Text').  I have found that Delphi
>1.0 is limiting me to about 32,000 rows.  This is because the values of ARow
>and ACol (the values passed to the Cells property) limit me to an integer
>value.  The TStringGrid properties ColCount and RowCount are both LongInt.
>There seems to be an inconsistency here.  In the meantime, does anybody know
>of a way to write to rows beyond the +/-32,000?  Or, does anybody know of an
>alternate TStringGrid component which will allow me to access rows beyond
>the 8-bit integer limit that TStringGrid imposes?  (It needs to be
>compatible with Delphi 1.0 and preferrably freeware---I know, I'm cheap...)

>Thanks a lot.

>Robert C. Ingebretsen

Even though RowCount and ColCount are Longint, if you set them to > 32K
the program falls over randomly even if you never use Cells. I've no
idea why Borland made them Longint at all, and suspect strongly that
somewhere internally they in fact aren't...

My solution is to have a small grid (50 rows), intercept scrolling
messages myself and use this as a window onto the full data set. I
suspect that any component would have to do something similar
internally.

Catherine.
--
Catherine Rees Lay

Re:TStringGrid: Cell property


I think Catherine is write, otherwise the component is going
to be too dependent (on the database size and on the RAM
available) on it's running environment to perform well (or to
perform at all).

Making a "window" over a file is not that dificult (it's just
tricky and demands good testing) and is possible to doit
even over a text file.

If you want to go fast and dont depend on resources, you
can manage the I/O on a lower level than database engines
and drivers.

A not so long time a go, in the "Turbo Pascal 6.0 over Dos"
era, I implemented a "component" (a "object") that could
read very long text files (I tried with over 1 GB) using a very
small buffer (some kbytes on the one digit range).

You just have to open the file as an untyped file, with some
convenient record size (usually 1 byte long) and use
BlockRead() to read the buffer window. To process the
scrollbar position you use the curren file cursor position,
that you can set using Seek(). And to get each file record
(= text line) you parse the buffer to find end-of-line marks
(usually CR/LF = #13#10).

Obviously, when you have the line you have to parse it to
get the individual fields.

Some code tips on untyped file I/O:

const
  _bufSize = 4000;
Type
  TBuffer  = array[1.._bufSize] of byte;
Var
  txtTable      : File;
  bytesLoaded,
  bytesToRead,
  fSize         : longint;
  buf           : TBuffer;
  ...
begin
  AssignFile(txtTable, 'txtTable');
  Reset(txtTable, 1);
  fSize := FileSize(txtTable);
  ...
    Seek(txtTable, newFilePos);
    BlockRead(txtTable, buf, bytesToRead, bytesLoaded);
  ...
  CloseFile(txtTable);
end;

--
=======================================
Paulo Gaspar
paulo_gas...@ip.pt
=======================================

Catherine Rees Lay <Cather...@reeslay.demon.co.uk> wrote in article
<om$8tFAivQG0E...@reeslay.demon.co.uk>...

Quote

> In article <5v7nbr$c6...@news.aros.net>, "Robert C. Ingebretsen"
> <r.c.ingebret...@m.cc.utah.edu> writes

> > I am manually reading a text database file to a TStringGrid using the
Cells
> >property (i.e. TStringGrid.Cells[1,3] := 'Text').  I have found that
Delphi
> >1.0 is limiting me to about 32,000 rows.  This is because the values of
ARow
> >and ACol (the values passed to the Cells property) limit me to an
integer
> >value.  The TStringGrid properties ColCount and RowCount are both
LongInt.
> >There seems to be an inconsistency here.  In the meantime, does anybody
know
> >of a way to write to rows beyond the +/-32,000?  Or, does anybody know
of an
> >alternate TStringGrid component which will allow me to access rows
beyond
> >the 8-bit integer limit that TStringGrid imposes?  (It needs to be
> >compatible with Delphi 1.0 and preferrably freeware---I know, I'm
cheap...)

> >Thanks a lot.

> >Robert C. Ingebretsen

> Even though RowCount and ColCount are Longint, if you set them to > 32K
> the program falls over randomly even if you never use Cells. I've no
> idea why Borland made them Longint at all, and suspect strongly that
> somewhere internally they in fact aren't...

> My solution is to have a small grid (50 rows), intercept scrolling
> messages myself and use this as a window onto the full data set. I
> suspect that any component would have to do something similar
> internally.

> Catherine.
> --
> Catherine Rees Lay

Re:TStringGrid: Cell property


Since reading over 32000 items manually from a db into a stringgrid might
take some time you should limit this capability to the integer maximum and
use another trick that will help speeding up you program.
Why not make two navigator buttons that will allow you to jump to the next
or previous 30000 records?

Jack

Quote
Robert C. Ingebretsen wrote in message <5v7nbr$c6...@news.aros.net>...
> I am manually reading a text database file to a TStringGrid using the
Cells
>property (i.e. TStringGrid.Cells[1,3] := 'Text').  I have found that Delphi
>1.0 is limiting me to about 32,000 rows.  This is because the values of
ARow
>and ACol (the values passed to the Cells property) limit me to an integer
>value.  The TStringGrid properties ColCount and RowCount are both LongInt.
>There seems to be an inconsistency here.  In the meantime, does anybody
know
>of a way to write to rows beyond the +/-32,000?  Or, does anybody know of
an
>alternate TStringGrid component which will allow me to access rows beyond
>the 8-bit integer limit that TStringGrid imposes?  (It needs to be
>compatible with Delphi 1.0 and preferrably freeware---I know, I'm cheap...)

>Thanks a lot.

>Robert C. Ingebretsen

Re:TStringGrid: Cell property


The Orpheus components from TurboPower have a grid component with a
limit of about 2 billion rows and columns. You have to manage the
information storage yourself, but this does let you do your own caching,
and you don't have to read the data until it actually needs to be
displayed.

In article <01bcbfb7$2df543a0$3300a...@robertc.xrs>, adas
<robert.ce...@eunet.si> writes

Quote
>>  I am manually reading a text database file to a TStringGrid using the
>Cells
>> property (i.e. TStringGrid.Cells[1,3] := 'Text').  I have found that
>Delphi
>> 1.0 is limiting me to about 32,000 rows.  This is because the values of
>ARow
>> and ACol (the values passed to the Cells property) limit me to an integer
>> value.  The TStringGrid properties ColCount and RowCount are both
>LongInt.
>> There seems to be an inconsistency here.  In the meantime, does anybody
>know
>> of a way to write to rows beyond the +/-32,000?  Or, does anybody know of
>an
>> alternate TStringGrid component which will allow me to access rows beyond
>> the 8-bit integer limit that TStringGrid imposes?  

>hum, you mean 16-bit integer

>> Robert C. Ingebretsen

>It would surely be possible, why not, but
>1. think about memory usage:
>each cell uses at least 12 bytes+string buffer, so if a 1K record is spread
>accross 10 cells it would use 1148 bytes * 32000 records is over 33 MBYTES,
>however re-allocations also take space.
>Do the following test: create two string lists (max 16k items each) and
>fill them with full string(255). Calculated usage would be 8MB, actual will
>be much more.
>2. think about load time
>3. think about browsing grid with over 32000 rows
>.....

>Maybe you should re-think the scope.
>Just an idea.

--
Mark Williams                   M...@polyhdrn.demon.co.uk

Polyhedron Software Ltd.        
Programs for Programmers - QA, Compilers, Graphics

************ Visit our Web site on http://www.polyhedron.co.uk/ ************

Other Threads