Zeoslib - loop over calculated fields
I have a Delphi 7 project using Zeoslib 6.6.6 and Sqlite3. On the form I have a Zquery selecting everything out of a 开发者_开发技巧sample database table along with a bunch of calcuated fields (TFloatField; TCurrencyField). The OnCalcFields event of the query runs fine and all field values are set. However, when i try to loop over the dataset, I consistently get a 'List index out of bounds (62893)' exception, though i am well within the field count limit (the first calculated field of about 14).
Snippet: gd is a TStringGrid, ZQuery4 is a TZQuery
while not ZQuery4.Eof do
begin
row := row + 1;
gd.Cells[0, row] := IntToStr(gd.Row);
gd.Cells[1, row] := ZQuery4pid.Value; //Known column
gd.Cells[2, row] := FormatFloat('0.00', ZQuery4area.Value); //known column
for i := 3 to ZQuery4.FieldCount - 1 do
begin
field := Zquery4.Fields[i]; //crashes here when accessing the first calculated field.
if field.IsNull
then gd.Cells[i, row] := ''
else gd.Cells[i, row] := field.AsString;
end;
end;
The bizarre thing is that if i connect a DBGrid to the query it works fine. Any ideas?
What happens when gd.cells[x,row] exceeds the number of rows you have set in the string grid? Probably that's your error. If you set your stringgrid to have 62000 rows, great, that's your error. Otherwise, I suspect that you're hitting a limit.
I always used to have my string grid row count grow like this, with logic after row=row+1:
if gd.RowCount<=row then gd.RowCount := row+1;
If however you really are getting this error at 60k+ stringgrid rows, it is possible that instead what is happening is you are hitting a string grid row length limit.
Since you haven't obviously posted ALL your code, it's hard to know what sets the row count in the string grid where, and how it grows.
In the case that you've hit a limit beyond which a StringGrid no longer operates, I suggest you drop StringGrid and use ExgridView or some other virtual gridview that can handle a very very large amount of data.
I seem to have stumbled across at least a workaround: changing
gd.Cells[i, row] := field.AsString;
to
gd.Cells[i, row] := field.DisplayText;
seems to have solved the problem.
精彩评论