Einzelnen Beitrag anzeigen

MPeters

Registriert seit: 20. Nov 2022
9 Beiträge
 
#1

Unerklärliche Zugriffsverletzung

  Alt 13. Apr 2023, 09:23
Hallo,

ich bin gerade am Verzweifeln. Ich erhalte eine Zugriffsverletzung in folgendem Code:

Delphi-Quellcode:
constructor TVisibleTreeNode.Create(theParentBox:TAnchestorClass; theName,theImage:string; theX,theY:longint; theCaption:string);
var imgPtr: ImageType;
begin

  FParentBox := theParentBox;
  FName := theName;
  FLeft := theX;
  FTop := theY;
  FCaption := theCaption;
  FOnClick := @Click;

  imgPtr := LoadImage(theImage);
  
  FNodeImage := TVisibleNodeImage.Create(FParentBox,FName,FLeft,FTop,imgPtr.width,imgPtr.height,imgPtr,@ImageClick);
  inherited Create(FParentBox,FName,FLeft+FNodeImage.Width+6,FTop+7,theCaption);

  FClicked := false;
  FExpanded := false;

  FNode.VisibleClass := self; //AN DIESER STELLE DIE ACCESS VIOLATION
end;
Delphi-Quellcode:
  TVisibleTreeNode = class(TAnchestorClass)
  private
    FParentBox: TAnChestorClass;
    FLeft,
    Ftop,
    FWidth,
    FHeight: Integer;
    
    FName: String;
    FImage: String;
    FCaption: String;
    FClicked: Boolean;
    FExpanded: Boolean;
    FOnClick: TClickEvent;
    FNode: TNode;
    FNodeImage: TVisibleNodeImage;
    
    function GetCaption: String;
    procedure SetCaption(AValue: String);
    procedure SetImage(AValue: String);
    procedure SetLeft(AValue: Integer);
    procedure SetTop(AValue: Integer);
    procedure SetWidth(AValue: Integer);
    procedure SetHeight(AValue: Integer);
    procedure ImageClick(param: String);
  public
    constructor Create(theParentBox:TtuiBox; theName,theImage:string; theX,theY:longint; theCaption:string);

    procedure Click(Sender: TObject; mX, mY: Integer);
    property OnClick: TClickEvent read FOnClick write FOnClick;
  end;
Unten die Definition der Klasse und nun noch die Definition des Node:

Delphi-Quellcode:
  TNode = class(TObject)
  private
    FCompare: TCompareFunc;
    FCaption: String;
    FParent: TNode;
    FNext: TNode;
    FNumber: Integer;
    FSubnodes: TNodes;
    FVisibleClass: TObject;

    function GetCount: Integer;
    function GetNodes(Index: Integer): TNode;
  public
    constructor Create(aParent: TNode; CompareFunc: TCompareFunc; aCaption: String);
    destructor Destroy; override;

    procedure Add(ParentNode: TNode; aNode: TNode);
    procedure AddSubnode(aParentNode: TNode; aNode: TNode); //Neuen Sub Knoten hinzufügen

    property Caption: String read FCaption write FCaption;
    property Nodes[Index: Integer]: TNode read GetNodes; //Die Blätter
    property Count: Integer read GetCount; //Anzahl Blätter
    property Parent: TNode read FParent write FParent;
    property Next: TNode read FNext write FNext;
    property Number: Integer read FNumber write FNumber;
    [B]property VisibleClass: TObject read FVisibleClass write FVisibleClass;[/B]
  end;
Warum tritt dese Zugriffsverletzung hier auf?
  Mit Zitat antworten Zitat