Excellent.
I love arrays. I use them to hold data (array of a record) for data in/out of the application. I use these in lieu of data-aware controls. My options are much greater if I do not use data-aware controls.
Here is how I implement dynamic arrays:
1) declare a record TrecAddress = record Name: string; Address: string; City: string; State: string; Zip: string; end;
2) my dynamic array defined: TaryAddressRec = array of TrecAddress;
3) gather some data in a query, then iterate through the query to dimension the array size var nCount: integer; aryWork: TaryAddressRec; begin nCount := 0; while (not qryWork.Eof) do begin inc(nCount); qryWork.Next; end;
// sets the size of the array to the number of rows found // since I deal with multipe DB types, Access, Oracle, MySQL, Elevate, I cannot rely on recordcount.
SetLength(aryWork,nCount); nCount := -1; while (not qryWork.Eof) do begin // may wish to initialize the array record here inc(nCount); // load the array aryWork[nCount].Name := qryWork.FieldByName('Name').AsString; aryWork[nCount].Address := qryWork.FieldByName(Address').AsString; ... qryWork.Next; end; // close connection end;
Anyway, I like arrays - they are
|