DELPHI结构问题 ( 积分: 100 )

  • 主题发起人 主题发起人 boycxd
  • 开始时间 开始时间
B

boycxd

Unregistered / Unconfirmed
GUEST, unregistred user!
type
Head=^SCHead;
SCHead=record
m_nType:integer;
m_lIndex:integer;
end;
type
pa=^Ask;
Ask=record
ID:integer;
aHead:Head;
end;
这样的结构怎么操作?
如:
var
xx:pa
begin
......(请帮个忙补全代码)
xx.aHead.m_nType:=1;
......
end;
 
var
xx:Ask
begin
//......(请帮个忙补全代码)
//这里不需要任何代码
xx.aHead.m_nType:=1;
......
end;
 
var
xx:pa
begin
//......(请帮个忙补全代码)
try
GetMem( xx,Sizeof( xx));
xx.aHead.m_nType:=1;
finally
FreeMem(xx);
end;
end;
這麼簡單問題以後還是自己找一下基本的書吧
 
运行出错!不知道为什么?
 
new(xx);
new(xx^.aHead);
 
var
xx: pa;
TmpHead: Head;
begin
New(TmpHead);
try
New(xx);
xx.aHead := TmpHead;
try
xx.aHead.m_nType:=1;
ShowMessage(IntToStr(xx.aHead.m_nType));
finally
Dispose(xx);
end;
finally
Dispose(TmpHead);
end;
end;
 
//模仿楼上的,呵呵。
var
xx: pa;
TmpHead: Head;
begin
GetMem(TmpHead, SizeOf(Head));
try
GetMem(xx, SizeOf(pa));
xx.aHead := TmpHead;
try
xx.aHead.m_nType:=1;
ShowMessage(IntToStr(xx.aHead.m_nType));
finally
FreeMem(xx);
end;
finally
FreeMem(TmpHead);
end;
end;
 
var
xx: pa;
begin
GetMem(xx,Sizeof(Ask));
GetMem(xx.aHead,Sizeof(SCHead));
try
xx.ID:=0;
xx.aHead.m_nType:=0;
xx.aHead.m_lIndex:=0;
finally
FreeMem(xx.aHead);
FreeMem(xx);
end;
end;
 
多人接受答案了。
 
后退
顶部