Consider my sample code:
var p512Sector: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^, ...);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.