I have a form with a DBGrid and a DBNavigator on it. In Delphi I could use the folowing code to keep a user from moving off the record ( any changes they have made are automatically saved if they move off the record ) if the Dataset was in dsEdit or dsInsert mode. I tried using the same code in this Lazarus project and it doesn't work. Any ideas why it isn't working? BTW, I'm new to Freepascal and the Lazarus IDE. Below is the code.
Thanks,
TD
procedure TfrmMain.DBNavigator1BeforeAction(Sender: TObject;
Button: TDBNavButtonType);
begin
try
// cancels navigation when in INSERT or EDIT mode
if DataModule1.Datasource1.State in [dsInsert, dsEdit] then
begin
if (Button = nbFirst) Or (Button = nbPrior)
Or (Button = nbNext) Or (Button = nbLast) then
begin
Beep;
SysUtils.Abort;
end;
end;
// cancels insert, delete, and refresh button click while in EDIT mode
if DataModule1.Datasource1.State in [dsEdit] then
begin
if (Button = nbInsert) Or (Button = nbRefresh)
Or (Button = nbDelete) then
begin
Beep;
SysUtils.Abort;
end;
end;
// cancels delete and refresh button click while in INSERT mode
if DataModule1.Datasource1.State in [dsInsert] then
begin
if (Button = nbRefresh) Or (Button = nbDelete) then
begin
Beep;
SysUtils.Abort;
end;
end;
except
on E : Exception do
begin
showmessage('Exception message = '+E.Message);
end;
end;
end