Subject More on Access violation in fbclient
Author petesouthwest
Hi

Sorry to essentially re-post, I wondered if the whole story plus
some code might help shed light on the problem.
background:
I have a project that includes 2 procedures, that use 2 separate
query components. The first procedure,(createNewRecordProject2)
clears the first query's sql, adds a new simple 'select * from
table1 where' style statement, opens the query and then does a
record count. The second procedure (not shown below as problem now
moved)uses a different query to access data in the same database
table ie table1. If i run procedure1, then procedure 2 and then
procedure 1 again, I get the error access violation in module
fbclient.dll when the first procedure does the recordcount in the
second call.

I wasn't sure why this was happening but as suggested I have
fixed that problem by changing the query.recordcount to code that
uses a 'select count(*) from table1' sql code. However the problem
now occurs on a table.active:=true; statement in the TabSheet13Show.
The problem is 100% repeatable but only on 1 sequence of
events/procedures that involve several queries and tables being
activated/deactivated and a 'post'. Change the sequence and
everything works fine.

My transaction component is set to autocommit.

I have pasted below slightly simplified versions (left out some of
the non db stuff) of the procedures in the order that causes the
error. Change the order that these procedures are executed and the
error does not happen.

Hopefully this extra info will help someone shed some light on this
for me!

Thanks
Pete

The procedures in the order that causes the error:

procedure tform1.createNewRecordProject2;
var
queryString:string;
begin
//check if record exists, query for same student and module
//changed to get round using recordcount
queryString:='SELECT count(*) FROM PROJECT2 where candidateNo="' +
DBEdit3.EditText+'"';
with datamodule2.qryProject2 do
begin
close;
sql.Clear;
sql.add(queryString);
open;
end;
if datamodule2.qryProject2.fieldbyname('count').asinteger=0
then // add new record
begin
queryString:='SELECT * FROM PROJECT2 where
candidateNo="' + DBEdit3.EditText+'"';
with datamodule2.qryProject2 do
begin
close;
sql.Clear;
sql.add(queryString);
open;
insert;
fieldbyname
('candidateNo').asstring:=dbEdit3.edittext;
post;
end;
end
else
begin
queryString:='SELECT * FROM PROJECT2 where
candidateNo="' + DBEdit3.EditText+'"';
with datamodule2.qryProject2 do
begin
close;
sql.Clear;
sql.add(queryString);
open;
edit; // this stops the av error
post; // this stops the av error
end;
end;


end;

procedure saveMarks(score:integer;sectionMarkName:string;);
begin
with datamodule2.qryProject2 do
begin
open;
edit;
fieldbyname(sectionMarkName).value:=score;
post;
end;

end;

procedure saveMarks1(score1:integer;sectionMarkName:string;);
begin

with datamodule2.qryProject2 do
begin
open;
edit;
fieldbyname(sectionMarkName).value:=score;
end;
calcTotal;
end;

procedure calcTotal;
var
total:integer;
begin
total:=datamodule2.qryProject2.fieldbyname('subtotal1').AsInteger+
datamodule2.qryProject2.fieldbyname('subtotal2').AsInteger+
datamodule2.qryProject2.fieldbyname('subtotal3').AsInteger;
with datamodule2.qryProject2 do
begin
edit;
fieldbyname('total').value:=total;
Post;
end;

end;

procedure TForm1.TabSheet1Hide(Sender: TObject);
begin
datamodule2.qryStudent.Active:=false;
datamodule2.query2.Active:=false;
datamodule2.query3.active:=false;

end;

procedure TForm1.TabSheet1Show(Sender: TObject);
begin
datamodule2.qryBriefCase.Active:=false;
datamodule2.tblCWmarks.Active:=false;
datamodule2.tblStudent.active:=false;
datamodule2.qryDeleteClass.active:=false;
datamodule2.qryClass.Active:=false;
datamodule2.qryProject2.active:=false;
datamodule2.qryFBAll.active:=true;
datamodule2.qryStudent.Active:=true;
datamodule2.query2.Active:=true;
datamodule2.query3.Active:=true;
end;

procedure tform1.createNewRecordProject2;
var
queryString:string;
begin
//check if record exists, query for same student and module
//changed to get round using recordcount
queryString:='SELECT count(*) FROM PROJECT2 where candidateNo="' +
DBEdit3.EditText+'"';
with datamodule2.qryProject2 do
begin
close;
sql.Clear;
sql.add(queryString);
open;
end;
if datamodule2.qryProject2.fieldbyname('count').asinteger=0
then // add new record
begin
queryString:='SELECT * FROM PROJECT2 where
candidateNo="' + DBEdit3.EditText+'"';
with datamodule2.qryProject2 do
begin
close;
sql.Clear;
sql.add(queryString);
open;
insert;
fieldbyname
('candidateNo').asstring:=dbEdit3.edittext;
post;
end;
end
else
begin
queryString:='SELECT * FROM PROJECT2 where
candidateNo="' + DBEdit3.EditText+'"';
with datamodule2.qryProject2 do
begin
close;
sql.Clear;
sql.add(queryString);
open;
edit; // this stops the av error
post; // this stops the av error
end;
end;

procedure TForm1.TabSheet13Show(Sender: TObject);
begin
datamodule2.qryBriefCase.Active:=false;
datamodule2.tblStudent.active:=true; //this line causes av error if
// post not done in procedure
// above
datamodule2.tblCWmarks2.Active:=true;
datamodule2.tblproject1.Active:=true;
datamodule2.qryClass.Active:=true;
end;