Einzelnen Beitrag anzeigen

bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.124 Beiträge
 
Delphi 11 Alexandria
 
#1

Add element into object list erzeugt eine access violation

  Alt 11. Jan 2022, 12:16
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;

Geändert von bernhard_LA (11. Jan 2022 um 12:19 Uhr)
  Mit Zitat antworten Zitat