请问关于DELPHI 指针加减法后MOVE 不接受的有关问题
请教关于DELPHI 指针加减法后MOVE 不接受的问题
此函数的大概意思是:比如 申请 1000个字节 我在0-100字节写入一段内容 然后在101-500写入另外一段内容
最后500-999写入一段内容。
请大家看最后两行 由于使用了指针移位加 使得相加再转型到Pointer的编程了Const类型
编译提示 :Constant cannot be passed as var parmeter;
最后发现MOVE的原型为
procedure Move(const Source; var Dest; count : Integer);
请教如何解决这个问题 谢谢!
------解决方案--------------------
试试这个:先将P赋值,MOVE前加上一句:
P := Pointer(Integer(P)+Sizeof(TBitMapFileHeader));
Move(FImage.FBitmapInfo,P,FImage.FBitmapInfoSize);
procedure TDIB.DataToPointer(var P:Pointer);
var
BF: TBitmapFileHeader;
begin
if Empty then Exit;
if P <> nil then Exit;
if not FImage.FMemoryImage then
GdiFlush;
with BF do
begin
bfType := BitmapFileType;
bfOffBits := SizeOf(TBitmapFileHeader) + BitmapInfoSize;
bfSize := bfOffBits + FImage.FBitmapInfo^.bmiHeader.biSizeImage;
bfReserved1 := 0;
bfReserved2 := 0;
end;
GetMem(P,BF.bfSize);
Move(BF,P,SizeOf(TBitmapFileHeader));
Move(FImage.FBitmapInfo, Pointer(Integer(P)+Sizeof(TBitMapFileHeader)),FImage.FBitmapInfoSize);
move(FImage.FPBits, Pointer(Integer(P)+Sizeof(TBitMapFileHeader)+FImage.FBitmapInfoSize), FImage.FBitmapInfo.bmiHeader.biSizeImage);
end;
此函数的大概意思是:比如 申请 1000个字节 我在0-100字节写入一段内容 然后在101-500写入另外一段内容
最后500-999写入一段内容。
请大家看最后两行 由于使用了指针移位加 使得相加再转型到Pointer的编程了Const类型
编译提示 :Constant cannot be passed as var parmeter;
最后发现MOVE的原型为
procedure Move(const Source; var Dest; count : Integer);
请教如何解决这个问题 谢谢!
------解决方案--------------------
试试这个:先将P赋值,MOVE前加上一句:
P := Pointer(Integer(P)+Sizeof(TBitMapFileHeader));
Move(FImage.FBitmapInfo,P,FImage.FBitmapInfoSize);