我在主窗口MainForm的formshow事件中遇到了这种问题:
假如说一个表有两个字段:任务ID,任务名称
我用node.text来显示姓名
用node.data属性来存储任务的ID号
任务的ID号(nvarchar(20))是六位:格式如:T10001
以下是在增加节点的时候填的代码:
IntRWID:=StrToInt(copy(StrRWID,2,5));//StrRWID是任务的ID,将任务编号的后五位保存到整形IntRWID任务ID中
node.Data:=Pointer(IntRWID);//并将其转换成Pointer类型存入节点的Data属性中
当在treeview中的节点被点击的时候我的代码如下:
Str2:=string(TreeView1.GetNodeAt(pt.X,pt.Y).Data);
然后让数据库中的任务表的substring(任务ID,2,5)
并用sqlserver2000语句来判断Str2和substring(任务ID,2,5)是否相等
但是会出现错误
代码://添加节点
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select a.jhgzbs ID,rwmc from hrp_xmjhb a,hrp_fpgzb b where b.cybs='''+MstaffID+''' and b.jhgzbs=a.jhgzbs and a.rwlxbs=3 and rwztbs!=2;');
adoquery1.Open;
if adoquery1.RecordCount>0 then
while not adoquery1.Eof do
begin
StrRWID:=trim(adoquery1.fieldbyname('ID').AsString);
IntRWID:=StrToInt(copy(StrRWID,2,11));
item:=trim(adoquery1.fieldbyname('rwmc').AsString);
subnode:=treeview1.Items.AddChild(DBcurnode,item);
subnode.Data:=Pointer(IntRWID);
adoquery1.Next;
end;
//双击事件
else if TreeView1.GetNodeAt(pt.X,pt.Y).Parent.Text='待办任务' then
begin
StrDBrwID:=string(TreeView1.GetNodeAt(pt.X,pt.Y).Data);
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select a.jhgzbs ID,rwmc from hrp_xmjhb a,hrp_fpgzb b where b.cybs='''+staffID+''' and b.jhgzbs=a.jhgzbs and a.rwlxbs=3 and rwztbs!=2 and substring(a.jhgzbs,2,11)='''+StrDBrwID+'''');
adoquery2.Open;
if adoquery2.RecordCount>0 then
begin
MDutyID:=adoquery2.FieldByName('ID').AsString;
ViewToDoTaskForm.ShowModal;
end;
end
假如说一个表有两个字段:任务ID,任务名称
我用node.text来显示姓名
用node.data属性来存储任务的ID号
任务的ID号(nvarchar(20))是六位:格式如:T10001
以下是在增加节点的时候填的代码:
IntRWID:=StrToInt(copy(StrRWID,2,5));//StrRWID是任务的ID,将任务编号的后五位保存到整形IntRWID任务ID中
node.Data:=Pointer(IntRWID);//并将其转换成Pointer类型存入节点的Data属性中
当在treeview中的节点被点击的时候我的代码如下:
Str2:=string(TreeView1.GetNodeAt(pt.X,pt.Y).Data);
然后让数据库中的任务表的substring(任务ID,2,5)
并用sqlserver2000语句来判断Str2和substring(任务ID,2,5)是否相等
但是会出现错误
代码://添加节点
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select a.jhgzbs ID,rwmc from hrp_xmjhb a,hrp_fpgzb b where b.cybs='''+MstaffID+''' and b.jhgzbs=a.jhgzbs and a.rwlxbs=3 and rwztbs!=2;');
adoquery1.Open;
if adoquery1.RecordCount>0 then
while not adoquery1.Eof do
begin
StrRWID:=trim(adoquery1.fieldbyname('ID').AsString);
IntRWID:=StrToInt(copy(StrRWID,2,11));
item:=trim(adoquery1.fieldbyname('rwmc').AsString);
subnode:=treeview1.Items.AddChild(DBcurnode,item);
subnode.Data:=Pointer(IntRWID);
adoquery1.Next;
end;
//双击事件
else if TreeView1.GetNodeAt(pt.X,pt.Y).Parent.Text='待办任务' then
begin
StrDBrwID:=string(TreeView1.GetNodeAt(pt.X,pt.Y).Data);
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select a.jhgzbs ID,rwmc from hrp_xmjhb a,hrp_fpgzb b where b.cybs='''+staffID+''' and b.jhgzbs=a.jhgzbs and a.rwlxbs=3 and rwztbs!=2 and substring(a.jhgzbs,2,11)='''+StrDBrwID+'''');
adoquery2.Open;
if adoquery2.RecordCount>0 then
begin
MDutyID:=adoquery2.FieldByName('ID').AsString;
ViewToDoTaskForm.ShowModal;
end;
end
PDataInfo=^TDataInfo;
TDataInfo=Record
ID: string;
end;使用的时候。
var NewP:PDataInfo; New(PDataInfo);
PDataInfo^.ID='sss';
treeview1.Items.AddChildObject(XXX,XXX,PDataInfo);取数的时候直接PDataInfo(XXX.DATA)^.ID
Trw=class
id :string;
name:string;
end;添加得时候:
subnode.Data:=Pointer(IntRWID);修改为
rw :=Trw.create();
rw.id:=StrRWID;
rw.name:=item;
subnode.Data:=rw;
点击事件
StrDBrwID:=string(TreeView1.GetNodeAt(pt.X,pt.Y).Data);
改为
rw:=TreeView1.GetNodeAt(pt.X,pt.Y).Data;
直接取rw中得值比较这样比操作指针方便简单多了。还不容易出错。
我也是刚学delphi
譬如说我的主窗口MainForm
我要在他的哪个地方来定义啊
是在var下面吗
需要声明吗
type
///在这写就行
TForm_MainFrame = class(TForm)
.... //你的页面对象
end;
用完后rw.free;
在每个地方每用一次都要先创建,然后释放啊
要是不释放的话,会不会出问题啊