T
tomol
Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,为什么我定义的一个结构可以写到EXE文件的尾部,却无法读出来呢??
type
MyColor = record
bRed: Boolean;
bWhite: Boolean;
bBlack: Boolean;
end;
已定义一个变量:
mycl: MyColor;
在写按钮里:
var
Target: TFileStream;
Size : integer;
begin
Target := TFileStream.Create('E:/Good/ts/good.exe', fmOpenWrite or fmShareExclusive);
try
Target.Seek(0, soFromEnd);
Target.WriteBuffer(mycl, Sizeof(mycl));
Size := Sizeof(mycl)+sizeof(Size);
Target.WriteBuffer(size, sizeof(Size));
finally
Target.Free;
end;
end;
用UltraEdit察看,已经写入
在读按钮里
var
Source: TFileStream;
Target: TMemoryStream;
Size: integer;
begin
Source := TFileStream.Create('E:/good/ts/good.exe', fmOpenRead or fmShareExclusive);
Target := TMemoryStream.Create;
try
Source.Seek(-Sizeof(Size), soFromEnd);
Source.ReadBuffer(Size, Sizeof(Size));
Source.Seek(-Size, soFromEnd);
Target.CopyFrom(Source, Size-Sizeof(Size));
Target.ReadBuffer(mycl, Sizeof(mycl));******//这一行出错
finally
Source.Free;
Target.Free;
end;
end;
请问为什么??
type
MyColor = record
bRed: Boolean;
bWhite: Boolean;
bBlack: Boolean;
end;
已定义一个变量:
mycl: MyColor;
在写按钮里:
var
Target: TFileStream;
Size : integer;
begin
Target := TFileStream.Create('E:/Good/ts/good.exe', fmOpenWrite or fmShareExclusive);
try
Target.Seek(0, soFromEnd);
Target.WriteBuffer(mycl, Sizeof(mycl));
Size := Sizeof(mycl)+sizeof(Size);
Target.WriteBuffer(size, sizeof(Size));
finally
Target.Free;
end;
end;
用UltraEdit察看,已经写入
在读按钮里
var
Source: TFileStream;
Target: TMemoryStream;
Size: integer;
begin
Source := TFileStream.Create('E:/good/ts/good.exe', fmOpenRead or fmShareExclusive);
Target := TMemoryStream.Create;
try
Source.Seek(-Sizeof(Size), soFromEnd);
Source.ReadBuffer(Size, Sizeof(Size));
Source.Seek(-Size, soFromEnd);
Target.CopyFrom(Source, Size-Sizeof(Size));
Target.ReadBuffer(mycl, Sizeof(mycl));******//这一行出错
finally
Source.Free;
Target.Free;
end;
end;
请问为什么??