pDword 转为string用inttostr 为什么不行??(0分)

  • 主题发起人 主题发起人 caoliu
  • 开始时间 开始时间
C

caoliu

Unregistered / Unconfirmed
GUEST, unregistred user!
pDword 转为string用inttostr 为什么不行??
A=PDword
inttostr(A)
编译报:[Error] systems.pas(169): There is no overloaded version of 'IntToStr' that can be called with these arguments
 
inttostr(A^)
 
编译 is ok thanks
inttostr(A^),A^ 是什么
 
A^, A是一个指针, A^是这个指针指向的数值
 
hardserial:string;
harddrives:PDword;
Serial1,Serial2:Dword
Serialnumber:array[0..255] of char
if GetVolumeInformation('c:/', Serialnumber, SizeOf(Serialnumber),harddrives,Serial1,Serial2, nil, 0) then
[red]hardserial:= inttostr(harddrives ^);[/red]
with TreeView1.Items.AddChild(TreeView1.Items[8],'硬盘: '+hardserial) do
begin
ImageIndex:=TreeView1.Items.Item[8].ImageIndex +4;
SelectedIndex:=TreeView1.Items.Item[8].SelectedIndex +4;
end;
语法 is ok
但到红字的地方报错
 
你的HardDrives没有分配空间

换成

HardDrivers : Word

GetVolumeInformation('c:/', Serialnumber, SizeOf(Serialnumber),@harddrives,Serial1,Serial2, nil, 0)
 
is ok
为什么?
GetVolumeInformation中参数harddrives应为PDword呀!
@harddrives是什么?
 
我来解释吧。@harddrivers是取变量harddrivers的地址。
原来你的代码中没有为harddrivers分配空间,也就是说,harddrivers访问的是
空地址(nil),会出现内存访问错误。而换成HardDrivers:Word之后,由于是个
变量,系统会自动为变量分配内存空间,这时@harddrivers指向合法地址,
自然把他作为参数传递给API函数就不会出错。
 
同意楼上的解释.
其实指针是一个整型数,也是可以转换成string的。
 
接受答案了.
 
后退
顶部