Problems with bookmarks after insert


2004-03-03 12:59:25 PM
delphi95
Hi,
I have written following procedure to handle query updates in multiple components.
OnAfterPost event I am calling this to update queries containing tablename in their sql.
But I have a problem. When I this call this OnPost event of a tadoquery It also tries to
refresh itself. If dataaset is in edit mode no problem but if I call after inserting a
record, a bookmark exception raises.
I can't ignore tadoquery that makes problem by looking its state propery. Its not in
edit or insert mode after posting.
I can stop this by passing a paramater to except caller form itself but I want to know why
I am receiving invalid bookmark exception. Even I use bookmarkvalid function problem
persists.
example: dmAna.RefreshDatasets('customers', Application);
procedure TdmAna.RefreshTables(TableName: string; Component: TComponent);
var
i: integer;
ABookmark: Pointer;
begin
if Component <>Sender then
for i:=0 to Component.ComponentCount - 1 do
begin
if Component.Components[i] is TADOQuery then
with TADOQuery(Component.Components[i]) do
begin
if Active and (State <>dsEdit) and (State <>dsInsert) then
if (Pos(TableName, SQL.Text)>0) then
begin
ABookmark := GetBookmark;
DisableControls;
Requery;
if BookmarkValid(ABookmark) then GotoBookmark(ABookmark);
EnableControls;
end;
end;
if Component.Components[i] is TComponent then
RefreshTables(Tablename, Component.Components[i]);
end;
end;
Regards,