ADOTable problem


Here:

procedure TForm2.ADOTable1AfterOpen(DataSet: TDataSet);
var AutoIncCount : Integer;
begin
ADOTable1.Sort := 'ID DESC' ;
AutoIncCount := ADOTable1.Fieldbyname('Member_ID').Asinteger;
cxTextEdit1.Text :=  inttostr(AutoIncCount + 1) ;
cxTextEdit2.SetFocus;
end;

procedure TForm2.ADOTable1AfterScroll(DataSet: TDataSet);
begin
wwdblookupcombo1.text := ADOTable1.FieldByName('Member_ID').AsString  ;
StatusBar1.Panels[0].Text := ' All records :' +IntToStr(ADOTable1.recordcount);
StatusBar1.Panels[1].Text:= ' Current record :'  +inttostr(ADOTable1.RecNo);
end;

Problem is this:
How do I prevent the program from crashing down if the adotable1 is empty
at runtime??
VrtnarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pcsentinelCommented:
procedure TForm2.ADOTable1AfterOpen(DataSet: TDataSet);
var AutoIncCount : Integer;
begin
 if not ADOTable1.Eof then
 begin
    ADOTable1.Sort := 'ID DESC' ;
   AutoIncCount := ADOTable1.Fieldbyname('Member_ID').Asinteger;
   cxTextEdit1.Text :=  inttostr(AutoIncCount + 1) ;
  cxTextEdit2.SetFocus;
 end;
end;

procedure TForm2.ADOTable1AfterScroll(DataSet: TDataSet);
begin
 if not (ADOTable1.Bof) and (ADOTable1.Eof) then
 begin
    wwdblookupcombo1.text := ADOTable1.FieldByName('Member_ID').AsString  ;
    StatusBar1.Panels[0].Text := ' All records :' +IntToStr(ADOTable1.recordcount);
    StatusBar1.Panels[1].Text:= ' Current record :'  +inttostr(ADOTable1.RecNo);
  end;
end;
0
VrtnarAuthor Commented:
It does not work right...
The only way it seems to work is :

procedure TForm2.ADOTable1AfterScroll(DataSet: TDataSet);
begin
if not ADOTable1.Bof then
 begin ....

Why is it when I delete last record from table
StatusBar1.Panels[1].Text:= ' Current record :'  +inttostr(ADOTable1.RecNo);
statusbar displays  -1  ???
0
Amir AzhdariCommented:
Vrtnar
use  ADOTable1.RecordCount in the events i mean :

procedure TForm2.ADOTable1AfterOpen(DataSet: TDataSet);
var AutoIncCount : Integer;
begin
 if ADOTable1.RecordCount>0 then
 begin
    ADOTable1.Sort := 'ID DESC' ;
   AutoIncCount := ADOTable1.Fieldbyname('Member_ID').Asinteger;
   cxTextEdit1.Text :=  inttostr(AutoIncCount + 1) ;
  cxTextEdit2.SetFocus;
 end;
end;


procedure TForm2.ADOTable1AfterScroll(DataSet: TDataSet);
begin
 if AdoTable1.RecordCount then
 begin
    wwdblookupcombo1.text := ADOTable1.FieldByName('Member_ID').AsString  ;
    StatusBar1.Panels[0].Text := ' All records :' +IntToStr(ADOTable1.recordcount);
    StatusBar1.Panels[1].Text:= ' Current record :'  +inttostr(ADOTable1.RecNo);
  end;
end;
0
Amir AzhdariCommented:
procedure TForm2.ADOTable1AfterScroll(DataSet: TDataSet);
begin
 if AdoTable1.RecordCount>0 then
 begin
    wwdblookupcombo1.text := ADOTable1.FieldByName('Member_ID').AsString  ;
    StatusBar1.Panels[0].Text := ' All records :' +IntToStr(ADOTable1.recordcount);
    StatusBar1.Panels[1].Text:= ' Current record :'  +inttostr(ADOTable1.RecNo);
  end;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pcsentinelCommented:
I think the reason is that because its an empty recordset then there is no current record number so it returns a default '-1', use the code below

procedure TForm2.ADOTable1AfterScroll(DataSet: TDataSet);
begin
 if not (ADOTable1.Bof) and (ADOTable1.Eof) then
 begin
    wwdblookupcombo1.text := ADOTable1.FieldByName('Member_ID').AsString  ;
    StatusBar1.Panels[0].Text := ' All records :' +IntToStr(ADOTable1.recordcount);
    StatusBar1.Panels[1].Text:= ' Current record :'  +inttostr(ADOTable1.RecNo);
  end
  else
  begin
    StatusBar1.Panels[0].Text := ' All records : 0';
    StatusBar1.Panels[1].Text:= '';
  end;
end;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.