【发布时间】:2017-07-19 18:26:07
【问题描述】:
在我的代码迁移过程中,我遇到了 Delphi 2010 和 Delphi Berlin(上次更新)之间的问题...... 我做了一个简单的代码来演示一个奇怪的行为......
我有一个使用 TList(前一个)和 TList(来自 Generics.Collections)的应用程序 我知道这段代码(如下)对你没有任何意义,但它是为了演示目的
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TTest = class
Name: string;
constructor Create(Nome: string);
end;
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FList: TList;
end;
var
Form1: TForm1;
implementation
uses
System.Generics.Collections;
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
tmpList: TList<TTest>;
begin
tmpList := TList<TTest>.Create;
tmpList.Add(TTest.Create('A'));
tmpList.Add(TTest.Create('B'));
tmpList.Add(TTest.Create('C'));
tmpList.Add(TTest.Create('D'));
tmpList.Add(TTest.Create('E'));
FList := TList(tmpList);
ShowMessage(TTest(FList[0]).Name);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FList := TList.Create;
end;
constructor TTest.Create(Nome: string);
begin
Name := Nome;
end;
end.
在 Delphi 2010 上,ShowMessage 显示“A”字符,但在 Delphi Berlin 上却引发了访问冲突
优化设置为 False 的两个应用程序
【问题讨论】:
标签: delphi