Autor Beitrag
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Do 16.03.06 01:09 
Ich wollte mich mit dem VirtualTreeView vertraut machen, komme jedoch kurz nach dem Start nicht mehr weiter:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, VirtualTrees;

type
  PData = ^TData;
  TData = record
    Text: WideString;
  end;

  TForm1 = class(TForm)
    VST: TVirtualStringTree;
    procedure FormCreate(Sender: TObject);
    procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
      Column: TColumnIndex; TextType: TVSTTextType;
      var CellText: WideString);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  D1, D2: TData;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  D1.Text:='Eins';
  D2.Text:='Zwei';

  VST.NodeDataSize:=SizeOf(TData);

  VST.AddChild(nil, Addr(D1));
  VST.AddChild(nil, Addr(D2));
end;

procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
var
  Data: PData;
begin
  Data:=Sender.GetNodeData(Node);
  Text:='abc'; // <-- warum geht das?
  CellText:=Data^.Text; // <-- da gibts eine EAccessViolation in oleaut32.dll
end;

end.


Was mache ich falsch?

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Do 16.03.06 07:58 
Das scheint mir doch recht umständlich/doppelt gemoppelt mit den Zeigern und Adressen.
Hast du dir schon Suche bei Delphi-Treff VIRTUALTREEVIEW durchgelsesen?
Grishnak Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Do 16.03.06 09:09 
Dank@user profile icondigi_c. Werde mir das Tutorial mal anschauen...

[... Zeit vergeht ...]

Aha, ".AddChild" allokiert selbstständig Speicher. Dann braucht man natürlich keine Daten-Rekords selbst zu deklarieren!

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!