开发者

Why do I get an access violation when I call FillChar?

Consider my sample code:

var p512S开发者_运维技巧ector:PByte;
.....
getmem(p512Sector, 262144);
FillChar( p512Sector,262144 ,0);

When I run the program, Delphi gives me an violation access error. Why?


Use FillChar(p512Sector^, 262144, 0) (note the dereferencing ^). Otherwise you are overwriting the pointer and the stuff behind in memory, not the allocated buffer.


FillChar expects an untyped variable. You should dereference the pointer:

FillChar(p512Sector^, ...);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜