執行環境:Win10x64, iOS 12.2
以下的程式碼,Win32 版可以正常執行 Button1Click 但在 iOS 則會出現
Run-time Error : Access violation at address xxxx
type
TMyObj = class(TObject)
public
Name, Value: string;
end;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
MyList: TList;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
var
temp: TMyObj;
begin
temp := MyList.Items[3];
Memo1.Lines.Add(temp.Name);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
myObj: TMyObj;
i: Integer;
begin
MyList := TList.Create();
for i := 0 to 10 do
begin
myObj := TMyObj.Create();
myObj.Name := 'Name'+i.ToString;
myObj.Value := 'Value'+i.ToString;
MyList.Add(myObj);
end;
end;
發現要改用 TListT<MyObj> 或 TObjectList<MyObj> 在 iOS 才會正常
uses Generics.Collections;
var
MyList: TObjectList<TMyObj>;
MyList := TObjectList<TMyObj>.Create();