Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1013
  • Last Modified:

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??
0
Vrtnar
Asked:
Vrtnar
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now