Error copying data in a DBGrid control to another using Zeos

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
elidorio2
Expert Boarder
Expert Boarder
Posts: 159
Joined: 20.08.2006, 05:37
Location: Tapejara -Pr
Contact:

Error copying data in a DBGrid control to another using Zeos

Post by elidorio2 »

Hello all,

I'm using the code below, to copy data from a dbgrid control to the other, this showing this error: bookmark was not found
I'm using Lazarus 1.2.6 with FPC 2.6.4 and Zeos Components windows 7 32.

What pose be wrong?

The code I am using is this:
procedure Tfrmprodgrupo.btnadicionaClick(Sender: TObject);
var
Idx: integer;
begin
try
if dbgprod.SelectedRows.Count > 0 then
begin
for Idx := 0 to dbgprod.SelectedRows.Count - 1 do
begin
// posiciona o dataset de origem no "n" registro selecionado
qryprod.GotoBookmark(pointer(dbgprod.SelectedRows.Items[Idx]));

// move os dados do dataset de origem para destino aqui
qrygrupo.Append;
qrygrupocd_fil.AsInteger := dmcad.filial;
qrygrupocd_grupo_trib.AsInteger := StrToInt(dbedtgrupo.Text);
qrygrupocd_prod.Value := qryprodcd_prod.Value;
qrygruponm_usuinc.AsString := frmmenu.usuariolog;
qrygrupodt_usuinc.AsDateTime := (Date + Time);
qrygrupo.Post;
qryprod.Refresh;
qrygrupo.Refresh;
qrycontprod.Close;
qrycontprod.Open;
qrycont2.Close;
qrycont2.ParamByName('cd_fil').AsInteger := dmcad.filial;
qrycont2.ParamByName('cd_grupo').AsInteger := StrToInt(dbedtgrupo.Text);
qrycont2.Open;
end;
end;
except
on E: Exception do
begin
raise Exception.Create('Ocorreu um erro:' + #13 + E.message);
end;
end;
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Error copying data in a DBGrid control to another using Zeos

Post by marsupilami »

Hello elidorio2,

I assume that the error happens at this line:
qryprod.GotoBookmark(pointer(dbgprod.SelectedRows.Items[Idx]));

I am not 100% sure but by using GotoBookmark you probably change the contents of SelectedRows. Maybe it is a better idea to first save the bookamrks to an array or something like that and then use that array for selecting the records you need to copy.
Best regards,

Jan
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

Re: Error copying data in a DBGrid control to another using Zeos

Post by markus »

Hi,
Maybe it is a better idea to first save the bookamrks to an array or something
Grid.SelectedRows is already type TBookmarkList.

I suggest using another variable of type TBookmark:

Code: Select all

TBookmark selRow = dbgprod.SelectedRows.Items[Idx];
qryprod.GotoBookmark(selRow);
btw:
you should also think about using Query.DisableControls before whole operation
and Query.EnableControls when it's finished - otherwise you'll see scrolling through query when going to selected rows.
Also save your current row to separate TBookmark, and go there after whole operation.


Best regards,
Marek
Post Reply