Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread |
Messages 31 to 31 of 31 total |
Inserting Record Efficiently |
Mon, Jun 4 2007 8:36 AM | Permanent Link |
Chris Erdal | Roy Lambert <roy.lambert@skynet.co.uk> wrote in
news:7361E5BD-4A5E-4143-91C7-24384325DC52@news.elevatesoft.com: > Chris > > > This is the fastest way I've managed to com up with. sg is the > TAdvStringGrid. I'm testing in fileserver mode since that's how I do > most things. > > > procedure TForm1.DoIt(BoxNo: integer); > var > lc: integer; > begin > sg.BeginUpdate; > ELN.IndexName := 'Company'; > sg.ClearRows(1, sg.RowCount - 1); > lc := 1; > if ELN.FindKey([BoxNo]) then begin > while ELN_fkCompanies.AsInteger = BoxNo do begin > sg.Cells[4, lc] := ELN_WhoFrom.AsString; > sg.Cells[3, lc] := ELN_Subject.AsString; > sg.Cells[2, lc] := ELN_TimeStamp.AsString; > sg.Cells[5, lc] := ELN_fkUsers.AsString; > ELN.Next; > inc(lc); > end; > end else lc := 2; > sg.RowCount := lc; > sg.FixedRows := 1; > sg.EndUpdate; > end; > > Roy Lambert > Roy, As I'm primarily interested in making my AdvStringGrid-handling generic, I've been usig this in my fillgrid routine: with grdMaster do begin BeginUpdate; try RowCount := pred(grdFixedRows); if btnFillGrid.Down then begin RowCount := dsMaster.DataSet.RecordCount + grdFixedRows; j := grdFixedRows; while not dsMaster.Dataset.EOF do begin FillGridRowFromCurrentRecord( grdMaster, j,dsMaster.Dataset); dsMaster.Dataset.Next; Inc(j); end; dsMaster.Dataset.First; HideColsAndRows; // sets "secret row" heights to 0, etc. end; finally EndUpdate; end; with: procedure TBaseAdvStrGrdForm.FillGridRowFromCurrentRecord( Grid: TAdvStringGrid; j: integer; aDSet: TDataset); var k: integer; aFld: TField; begin if aDSet = nil then Exit; with Grid do begin while (j >= rowcount) do // just in case rowcount := rowcount + 1; Cells[grdRecNoCol, j] := RecNoStr(aDSet.RecNo); // "Secret" Column grdRecNoCol contains the dataset's RecNo // for finding the dataset row when necessary for k := grdFixedCols to pred(Grid.ColCount) do begin aFld := aDSet.FindField(Grid.Cells[k, grdFieldNameRow]); // "Secret" Row grdFieldNameRow contains the fieldnames // in user-selectable order if (aFld = nil) or not aFld.Visible then // user-selectable continue; if (aFld.DataType = ftBoolean) and not (CellTypes[k, j] = ctDataCheckBox) then begin AddCheckBox(k, j, False, True); // doesn't set value yet end; if aFld.IsNull then Cells[k, j] := '' else try Cells[k, j] := aFld.Value; // "value" allows for localised // numeric formatting by grid different from database formatting, etc. except raise; end; end; end; end; It's not terribly fast, but these base forms are not intended for handling a huge amount of data at once. -- Chris (XP-Pro + Delphi 7 Architect + DBISAM 4.25 build 4 + EDB 1.03 build 1) |
« Previous Page | Page 4 of 4 | |
Jump to Page: 1 2 3 4 |
This web page was last updated on Saturday, April 27, 2024 at 08:52 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |