Hi all - I am pleased to have found Lazarus for GUI programming on Ubuntu!
I cannot figure out how to store and retrieve an integer value in a TTreeNode's Data property. Here is a simple sample program to demonstrate my efforts. Please note, I am only casting the variable "i" to a string in order to display the results in the textbox. However, an exception is thrown and the message is "Access Violation."
Your help will be appreciated. Thanks.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, ComCtrls, StdCtrls, SysUtils, FileUtil, LResources, Forms, Controls,
Graphics, Dialogs;
type
{ TForm1 }
TForm1 = class(TForm)
btnAdd: TButton;
btnDisplay: TButton;
txtDisplay: TEdit;
tree: TTreeView;
procedure btnAddClick(Sender: TObject);
procedure btnDisplayClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.btnAddClick(Sender: TObject);
var
node: TTreeNode;
begin
node := tree.Items.Add(nil, 'hello world');
node.Data := pointer(1);
end;
procedure TForm1.btnDisplayClick(Sender: TObject);
var
i: integer;
str: string;
begin
if (tree.Selected = nil) then begin
ShowMessage('Please select ''hello world'' item and click again');
exit
end;
try
i := integer(tree.Selected.Data);
str := string(i);
txtDisplay.Text := str;
except on E: Exception do begin
ShowMessage(E.Message);
end;
end;
end;
initialization
{$I unit1.lrs}
end.