Einzelnen Beitrag anzeigen

Benutzerbild von xZise
xZise

Registriert seit: 3. Mär 2006
Ort: Waldbronn
4.303 Beiträge
 
Delphi 2009 Professional
 
#1

TTreeNode soll auf ein anderes Objekt zeigen

  Alt 23. Apr 2007, 16:17
Hi... Ich bins wieder mit einem ziemlich dummen Problem ^^
Und zwar habe ich verschiedene TTreeNodes auf meiner TTreeView (oh wunder) und ein System wo die Dateien gespeichert sind. (Sozusagen sind die TreeNodes Repräsentanten)

Also möchte ich das Objekt, welches ich anlege, irgendwie in TTreeNodes speichern, ohne viel umzukrempeln.
Also dachte ich: Ich erstelle ein neues "TTreeNode" Objekt und füge diese Fehlende Eigenschaft hinzu:
Delphi-Quellcode:
unit uTTreeNodeEx;

interface

uses
   ComCtrls, uCode;

type
   TTreeNodeEx = class(TTreeNode)
  private
    FAssociatedWith: TMemoInformation;
    procedure SetAssociatedWith(const Value: TMemoInformation);
    function GetParent: TTreeNodeEx;
   published
    property AssociatedWith : TMemoInformation read FAssociatedWith write SetAssociatedWith;
  public
     property Parent: TTreeNodeEx read GetParent;
     constructor Create(AOwner : TTreeNodes);
  end;

implementation

{ TTreeNodeEx }

constructor TTreeNodeEx.Create(AOwner: TTreeNodes);
begin
  inherited;
  FAssociatedWith := nil;
end;

function TTreeNodeEx.GetParent: TTreeNodeEx;
begin
  Result := TTreeNodeEx(inherited Parent);
end;

procedure TTreeNodeEx.SetAssociatedWith(const Value: TMemoInformation);
begin
  FAssociatedWith := Value;
end;

end.
Wie man sieht nicht viel Code, wenn man von Parent und Create absieht.
Das Problem ist jetzt nur, wie kriege ich das im TreeView gespeichert...
Meine "Lösung":
Delphi-Quellcode:
var
  child : TTreeNodeEx;
begin
  child := TTreeNodeEx(tvMemolist.Items.AddChild(pParent, eTitle.Text));
  child.AssociatedWith := ...;
end;
Delphi-Quellcode:
procedure TfrmMain.tvMemolistChange(Sender: TObject; Node: TTreeNode);
var
  pParent : TTreeNodeEx;
begin
  pParent := TTreeNodeEx(Node);
  Showmessage(pParent.AssociatedWith.Name);
end;
Aber es hat nicht sein sollen => AV
Fabian
Eigentlich hat MS Windows ab Vista den Hang zur Selbstzerstörung abgewöhnt – mkinzler
  Mit Zitat antworten Zitat