Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   Add element into object list erzeugt eine access violation (https://www.delphipraxis.net/209697-add-element-into-object-list-erzeugt-eine-access-violation.html)

bernhard_LA 11. Jan 2022 12:16


Add element into object list erzeugt eine access violation
 
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;

himitsu 11. Jan 2022 12:18

AW: Add element into object list erzeugt eine access violation
 
inherited vergessen? :stupid:



Ist natürlich bissl doof, wenn alle Funktionen geheim sind und wir nix sehn.

bernhard_LA 11. Jan 2022 12:26

AW: Add element into object list erzeugt eine access violation
 
@ Danke & Volltreffer !



die alte version der Klasse war :

Delphi-Quellcode:

TPList = class(TobjectList<TPContent>)

    procedure SavetoFile(aFilename: String);

  end;
und da brauchte es keine Constructor in keine inherited :-)


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:07 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz