我已将以下代码作为 Android 应用程序构建并运行。该应用程序按预期工作,但关闭时我在 TIdSSLIOhandler 中遇到分段错误。Indy 组件是否与 FireMonkey 不兼容?
unit Main;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, IdIOHandler,
IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, FMX.Layouts, FMX.Memo,
FMX.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
http: TIdHTTP;
ioSocket: TIdSSLIOHandlerSocketOpenSSL;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
LiServer:string;
procedure DBCom(var retdata: TStringlist);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
{$R *.LgXhdpiPh.fmx ANDROID}
procedure TForm1.Button1Click(Sender: TObject);
var m: TMemoryStream;
retdata: TStringList;
i:integer;
begin
m:=TMemoryStream.Create;
//--- init data
retdata:=TStringList.Create;
retdata.Add('F=1');
//--- add data
retdata.Add('Data=1');
//--- send data to server database
DBCom(retdata);
for i := 0 to retdata.Count-1 do
memo1.Lines.Add(retdata[i]);
//--- free allocated resources
retdata.Free;
m.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var m: TMemoryStream;
retdata: TStringList;
i:integer;
begin
m:=TMemoryStream.Create;
//--- init data
retdata:=TStringList.Create;
retdata.Add('F=1');
//--- add data
retdata.Add('Data=A');
//--- send data to server database
DBCom(retdata);
for i := 0 to retdata.Count-1 do
memo1.Lines.Add(retdata[i]);
//--- free allocated resources
retdata.Free;
m.Free;
end;
//============ communication with DB
procedure TForm1.DBCom(var retdata:TStringlist);
var m: TMemoryStream;
errcode,i,msgid,status,id:Integer;
begin
m:=TMemoryStream.Create;
//--- send data to server database
http.Post(LiServer, retdata, m);
m.Position:=0;
retdata.LoadFromStream(m);
//--- free allocated resources
m.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
LiServer:='http://server.com/url.php';
end;
end.
该错误发生在 SSL_CTX_free(fContext) 行上的此过程中。
procedure TIdSSLContext.DestroyContext;
begin
if fContext <> nil then begin
SSL_CTX_free(fContext);
fContext := nil;
end;
end;