5,715
社区成员
发帖
与我相关
我的任务
分享
Delphi android 如果是使用一般的select语句 没有闪退,后面有些复杂的语句需要存储过程来处理 就会碰到闪退的问题
unit DatePostThread;
interface
uses System.SysUtils, System.Types, System.UITypes, System.Classes, IdHTTP,
IdComponent, Math, FMX.Forms,
FMX.Helpers.Android, Androidapi.JNI.Support, Androidapi.Helpers,
Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Net,
Androidapi.JNI.JavaTypes, Androidapi.JNI.Os, Datasnap.DBClient,
IOUtils, System.Permissions, UpdateApp, FMX.Types, FMX.Dialogs, FMX.StdCtrls;
type
TDatePostThread = Class(TThread)
protected
procedure Execute; override;
public
constructor Create(sql: String; FrameName: String; code: String;
Sender: TObject);
destructor Destroy(); override;
var
EexSql: String;
Frame: String;
Timecode: String;
From: TObject;
End;
implementation
uses uPubFUNCs, Main, Server, OrderOut;
constructor TDatePostThread.Create(sql: String; FrameName: String; code: String;
Sender: TObject);
begin
EexSql := sql;
Frame := FrameName;
Inherited Create(False);
// FreeOnterminate := True;
end;
destructor TDatePostThread.Destroy();
begin
Inherited Destroy;
end;
procedure TDatePostThread.Execute;
var
ClientDataSet: TClientDataSet;
begin
ClientDataSet := TClientDataSet.Create(TForm(From));
try
FMain.SQLConnection1.Open;
FMain.SQLConnection1.Connected := True;
ClientDataSet.ProviderName := 'DataSetProvider1';
ClientDataSet.RemoteServer := FMain.DSProviderConnection1;
EXCEPT
FMain.FDQuery1.Close;
FMain.FDQuery1.sql.Clear;
FMain.FDQuery1.sql.Add
('insert into DataPost(ModeName,ID,SqlStr) values(:ModeName,:ID,:SqlStr)');
FMain.FDQuery1.ParamByName('ModeName').Value := Frame;
FMain.FDQuery1.ParamByName('ID').Value := Timecode;
FMain.FDQuery1.ParamByName('SqlStr').Value := EexSql;
FMain.FDQuery1.ExecSQL;
exit;
end;
TServerMethods1Client.Create(FMain.SQLConnection1.DBXConnection)
.SqlExecLog(EexSql, FMain.Login);
ClientDataSet.Close;
ClientDataSet.CommandText := EexSql;
ClientDataSet.Open;
end;
end.
这是执行代码
SQL := 'exec spOrderOutDataPost ''' + PrintCodeList + ''',''' + AutoIDList +
''',''' + cInvCodeList + ''',''' + cBatchList + ''',''' + OutQtyList +
''',''' + Edit4.Text + ''',''' + Ptype + ''',''' +
Copy(WH, 1, pos('/', WH) - 1) + ''',''' + Copy(WH, pos('/', WH) + 1,
length(WH)) + ''',''' + Timecode + ''',''' + FMain.Login + ''',''' +
FMain.Password + ''',''' + FMain.LoginDate + '''';
DatePostThread := TDatePostThread.Create(SQL, '销售出库', Timecode, self);
这是调用代码
为什么执行存储过程 就可能出现闪退 ?
这是中间层的控件
存储过程是能够返回数据的,所以如果在SQL中执行存储过程,不要用ExecSQL,要用Open。
估计是你的存储过程返回了某些错误代码触发了异常,而你没有捕捉,而你的SQL连接是运行在主线程中的,线程中出现未捕捉的异常默认处理模型就是终止线程,主线程终止,你的程序就退出了。所以,程序的健壮性很重要~
这个应该与SQL语句没什么关系吧。