TreeNode.Data := Pointer(psmallint);psmallint := PSmannInt(TreeNode.Data)
解决方案 »
- delphi中使用rmreport控件打印dbgrid中的数据
- 用delphi完成学生信息管理系统
- 谁有ODAC 6.5啊???如果有的发份给我把谢谢 [email protected]
- 这个难题可称为世界之最了.大家进来帮我看看.delphi回调VC动态库返回不了结果啦...
- 问一个关于SQL语句的问题。
- 请教Delphi程序内存问题!
- ServerSocket/ClientSocket控件支不支持IPX/SPX协议啊?
- 用DEDE反编译出的PAS文件里面的事件都是汇编语言的,实在看不懂,怎么办?
- 关于用delphi制作报表打印程序的问题.
- 我需要在内存中做一个链表作为文件的缓冲,请问有什么方法可以动态的得到内存的地址。
- 怎样处理这个问题(不是很难)
- 各位高手帮帮小弟一把,请问如何将字符串中的数字提取出来?
PMyRec = ^TMyRec;
TMyRec = record
FName: string;
LName: string;
end;Assuming these types are used, the following code adds a node to TreeView1 as the last sibling of a specified node. A TMyRec record is associated with the added item. The FName and LName fields are obtained from edit boxes Edit1 and Edit2. The Index parameter is obtained from edit box Edit3. The item is added only if the Index is a valid value.procedure TForm1.Button1Click(Sender: TObject);var
MyRecPtr: PMyRec;
TreeViewIndex: LongInt;
begin
New(MyRecPtr);
MyRecPtr^.FName := Edit1.Text;
MyRecPtr^.LName := Edit2.Text;
TreeViewIndex := StrToInt(Edit3.Text);
with TreeView1 do
begin
if Items.Count = 0 then
Items.AddObject(nil, 'Item' + IntToStr(TreeViewIndex), MyRecPtr)
else if (TreeViewIndex < Items.Count) and (TreeViewIndex >= 0) then Items.AddObject(Items[TreeViewIndex], 'Item' + IntToStr(TreeViewIndex), MyRecPtr);
end;
end;After an item containing a TMyRec record has been added, the following code retrieves the FName and LName values associated with the item and displays the values in a label.procedure TForm1.Button2Click(Sender: TObject);begin
Label1.Caption := PMyRec(TreeView1.Selected.Data)^.FName + ' ' +
PMyRec(TreeView1.Selected.Data)^.LName;
end;
那么我写的程序错在那里,请帮我看一下
procedure TForm1.Button1Click(Sender: TObject);
var pp:psmallint;
aa:smallint;
begin
aa:=100;
pp:=@aa;
treeview1.Items.addobject(nil,'smallint',pointer(pp));
end;procedure TForm1.Button2Click(Sender: TObject);
var pp:psmallint;
begin
pp:=psmallint(treeview1.Selected.data);
edit1.text:=inttostr(pp^);
end;
aa释放,pp也释放,items中保存的东西都失效了。你在别的函数中读
取,当然没用了。如果你想保存aa的值,就直接:
treeview1.Items.addobject(nil,'smallint',pointer(aa));
用的时候:
edit1.text:=inttostr(smallint(treeview1.Selected.data));
谢谢!楼上的朋友,dream infotree 好用吗,哪儿下载呢?
是不是太浪费资源了?
var
pp:psmallint;
TmpItem:TTreeNode;
begin
New(pp);
PP^:=100;
aa:=100;
TmpItem:=TreeView1.Items.AddChild(nil,'smallint');
TmpItem.Data=pp;
end;procedure TForm1.Button2Click(Sender: TObject);
var pp:psmallint;
begin
pp:=psmallint(treeview1.Selected.data);
edit1.text:=inttostr(pp^);
end; 记得在TreeView的Items.Clear的时候要Dispose分配的指针内存
var
pp:psmallint;
TmpItem:TTreeNode;
begin
New(pp);
PP^:=100;
TmpItem:=TreeView1.Items.AddChild(nil,'smallint');
TmpItem.Data=pp;
end;procedure TForm1.Button2Click(Sender: TObject);
var pp:psmallint;
begin
pp:=psmallint(treeview1.Selected.data);
edit1.text:=inttostr(pp^);
end; 记得在TreeView的Items.Clear的时候要Dispose分配的指针内存