Why am I getting an access violation when calling FillChar?

Consider my sample code:

var p512Sector:PByte;
.....
getmem(p512Sector, 262144);
FillChar( p512Sector,262144 ,0);

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

+3
source share
2 answers

Use FillChar(p512Sector^, 262144, 0)(note dereferencing ^). Otherwise, you are rewriting the pointer and material in memory, not a dedicated buffer.

+11
source

FillCharexpects an untyped variable. You must dereference a pointer:

FillChar(p512Sector^, ...);
+5
source

Source: https://habr.com/ru/post/1775143/


All Articles