delphi - Insert DBGrid data into a multi-dimensional array -
i have set connection delphi pgsql using adoconnection, adoquery, datasource , dbgrid nowadays results of query. database contains 2 columns of values of type double, of thousands of rows, insert two-dimensional array.however, quite new not sure how insert contents of dbgrid array. help much appreciated.
first of if there thousands of rows need assign fields variables before reading rid of unnecessary text lookup time when using fieldbyname.
i dont't have delphi @ hand should work or @ to the lowest degree help started.
uses math; procedure processarray(adataset: tdataset); var field1: tfield; field2: tfield; len: integer; a: array of array[2] of double; begin len := 0; setlength(a, 0); field1 := adataset.fieldbyname('field1'); field2 := adataset.fieldbyname('field2'); adataset.first; while not adataset.eof begin inc(len); if len > length(a) setlength(a, len + min(len, 16384)); a[len - 1][0] := field1.value; a[len - 1][1] := field2.value; adataset.next; end; setlength(a, len); // process results in array end;
what alexsc suggesting utilize tadodataset.recordcount property set size of array initially. please note if tdataset not loaded database (uses server cursor example), recordcount not contain number of records , original solution above able cope this. made correction won't grow more 16k items @ 1 time , overhead @ 16k - 1 array entries. info tdataset "lazy loading" refer dbgrid read ahead capability using ado
please find code using recordcount below:
procedure processarray(adataset: tdataset); var field1: tfield; field2: tfield; len: integer; a: array of array[2] of double; begin len := 0; setlength(a, adataset.recordcount); field1 := adataset.fieldbyname('field1'); field2 := adataset.fieldbyname('field2'); adataset.first; while not adataset.eof begin a[len][0] := field1.value; a[len][1] := field2.value; inc(len); adataset.next; end; // process results in array here end;
arrays delphi dbgrid
No comments:
Post a Comment