Bonjour,
je fais face depuis plusieurs jours à un gros problème de fonctionnalité avec la tentative d'accéder au texte d'un TreeNode dans un TreeView posé sur une fiche et bien rempli, qui se solde par un SIGSEGV, le TreeNode semblant vide.
Le code est tout simple :
Je précise à tout hasard qu'on trouve partout sur le web ce type de code, exemple (à adapter) chez Embarcadero :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 procedure TForm1.FormCreate(Sender: TObject); begin if tv1.Items.Count = 0 then {If the tree is empty} with tv1.Items.AddFirst(nil, 'Root') do begin {Add the root node} Selected := true; ImageIndex := IMG_NODE_ROOT; SelectedIndex := IMG_NODE_ROOT; StateIndex := IMG_CHECKED; end; end; procedure TForm1.Button1Click(Sender: TObject); // fill tv var i, maxi: integer; begin maxi := 6; // création de 6 nodes for i:=0 to maxi-1 do with tv1.Items.Add(tv1.Selected, 'subnode'+IntToStr(i+1)) do MakeVisible; ShowMessage('Pause pour choisir un subnode, puis Button2 pour action'); end; procedure TForm1.Button2Click(Sender: TObject); // use it var i: integer; P: TPoint; HT: THitTests; AnItem: TTreeNode; begin P.X := 0; // happy compilo GetCursorPos(P); // 2 lignes nécessaires pour Linux, sinon valeurs X Y en vrac P := tv1.ScreenToClient(P); if tv1.Selected = nil then Exit else ShowMessage('on continue');// vu HT := tv1.GetHitTestInfoAt(P.X, P.Y); AnItem := tv1.GetNodeAt(P.X, P.Y); if AnItem <> nil then //ShowMessage('OnButton2: '+ AnItem.Text); // SIGSEGV ShowMessage('OnButton2: '+ AnItem.GetTextPath) // SIGSEGV // et là, je ne vois JAMAIS ces ShowMessage... end;
https://docwiki.embarcadero.com/Code...odeAt_(Delphi), alors si quelqu'un pouvait me dire ce qui m'échappe, je l'en remercie infiniment par avance.
Une dernière info : dans les options du treeview j'ai activé tvoRowSelect mais ça ne change rien.
Laz 3.8 FPC 3.2.2 Linux Debian uptodate.
Partager