相同的代码在XE8中正常工作在DX西雅图不起作用希望它只需要一些其他设置
我想使用SQLite将异常记录到数据库表中
使用下面的AddData调用将数据添加到表中,可以正常按下按钮
但是我无法让SQLite数据库从Application.OnException调用中添加数据
使用调试器看起来像添加行但它似乎删除自己
在交易中表现得像它一样,它会自动回滚
有谁知道为什么这不发布?
procedure TForm1.AppException(Sender: TObject; e: Exception);
begin
AddData(e.Message); //<--- this line gets called on exception but not adding data
Application.ShowException(e);
end;
procedure TForm1.AddData(aString: String);
begin
tb1.Append;
tb1.FieldByName('test').AsString := aString;
tb1.Post;
tb1.Close;
con1.close();
con1.Open();
tb1.Open();
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
AddData('btn1Click'); //this Works
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
raise Exception.Create('Error Message'); //cant get this to add into the DB
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
con1.Open();
if con1.Connected then begin
qry1.SQL.Clear;
qry1.SQL.Add
('Create Table if not Exists TEST(test char(255));');
qry1.ExecSQL;
tb1.Open();
end;
Application.OnException := AppException;
end;
这里的完整代码
https://github.com/dangas56/DelphiDXSeattle-ApplicationOnException-SQLite
从git中的代码重现的步骤
1 - 加载项目
2 - 单击“将数据添加到数据库”按钮&lt; - 应该工作
3 - 单击“无法添加到数据库”按钮&lt; - 无法添加行
使用FDTable组件似乎很有趣 香港专业教育学院改变了AddData调用在上面的工作方式
procedure TForm1.AddData(aString: String);
procedure AddUsingFDTable(aStr : String); <--Fails
var tbTest : TFDTable;
begin
tbTest := TFDTable.Create(nil);
try
tbTest.UpdateOptions.AutoCommitUpdates := true;
tbTest.UpdateOptions.UpdateMode := upWhereAll;
tbTest.Connection := con1;
tbTest.TableName := 'TEST';
tbTest.Open();
tbTest.Append;
tbTest.FieldByName('test').AsString := aStr;
tbTest.Post;
tbTest.Close;
finally
tbTest.Free;
end;
end;
procedure AddusingFDQuery(aStr : String); <--Works
var qry1 : TFDQuery;
begin
qry1 := TFDQuery.Create(nil);
try
qry1.Connection := con1;
qry1.SQL.Clear;
qry1.SQL.Add('insert into test (test) values ( :Testing )');
qry1.ParamByName('Testing').AsString := aStr;
qry1.ExecSQL;
finally
qry1.Free;
end;
end;
begin
AddUsingFDTable(aString); <--Fails
//AddusingFDQuery(aString); <--Works
tb1.Close;
con1.close();
con1.Open();
tb1.Open();
end;
任何人都可以告诉我为什么表格组件在被调用时没有发布?
procedure TForm1.AppException(Sender: TObject; e: Exception);
begin
AddData(e.Message); //<--- this line gets called on exception but not adding data
Application.ShowException(e);
end;