was ist denn an dem code sample unten falsch, warum kommt es hier zu einer
AV beim Einfügen eines neuen Elements ?
Delphi-Quellcode:
type
/// <summary>
/// read content between start search key and ending search key word
/// </summary>
TPContent =
class
InstanceType:
String;
text_startPos: Integer;
text_StopPos: Integer;
InstanceString:
String;
end;
type
TPList =
class(TobjectList<TPContent>)
private
fInfoStrlst: TStringList;
public
constructor Create;
destructor Destroy;
override;
procedure SavetoFile(aFilename:
String);
property InfoStrLst: TStringList
read fInfoStrlst
write fInfoStrlst;
end;
procedure TForm2.Button2Click(Sender: TObject);
var
aPlist: TPlist;
aPContent: TPContent;
i: Integer;
begin
aPlist := TPlist.Create;
for i := 0
to 1000
do
begin
aPContent := TPContent.Create;
aPContent.InstanceType := '
xxxxx';
aPContent.InstanceString := '
CCCCCCCC';
aPContent.text_startPos := 0;
aPContent.text_StopPos := 0;
aPlist.Add(aPContent);
// hier tritt der AV Fehler auf
end;
end;
Fehler
Delphi-Quellcode:
// Calculate the needed size of the heap object
t := PDynArrayTypeInfo( PByte(typeInfo) + PDynArrayTypeInfo(typeInfo).name );
elSize := t.elSize;