【发布时间】:2013-09-20 11:14:01
【问题描述】:
我有一个 Delphi 应用程序,它从文件中读取数据并将其存储在数组中。文件中的每一行都包含一个地址、lineTypeIndicator 和数据。这是算法(包含我认为很关键的代码):
AssignFile(inputFile, inFileName);
Reset(inputFile);
while not EOF(inputFile) do
begin
Readln(inputFile,fileLineBuffer);
if Copy(fileLineBuffer, 8, 2) = '01' then //Never managed to catch the error here
begin
break;
end;
//extract the address from the line and use it to determine max and min address.
end;
//Now that you have min and max address, use it to set the length of an char array
SetLength(memoryArray,(lastAddress - firstAddress) * 2);
Reset(inputFile);
while not EOF(inputFile) do
begin
Readln(inputFile,fileLineBuffer);
if Copy(fileLineBuffer, 8, 2) = '01' then //I caught all the errors here
begin
break;
end;
//extract the address and data from the fileLineBuffer and place it in the corresponding place in an array
end;
每次用户单击表单上的相应按钮时都会执行此代码。它在执行的前几次运行,但在几次运行后我得到了这个:
MyProgram.exe 出现错误消息:'在 0x00406111 处的访问冲突: 写入地址 0x00090d1c(这会有所不同)。进程停止。使用步骤 或运行以继续。
对我来说,这闻起来像是某种堆溢出。我试过替换
if Copy(fileLineBuffer, 8, 2) = '01' then
与
lineTypeBuffer := Copy(fileLineBuffer, 8, 2);
if lineTypeBuffer = '01' then
或
if (fileLineBuffer[8] = '0') and (fileLineBuffer[9] = '1') then
但它没有帮助。 关于我应该如何解决这个问题的任何建议?
附:尝试在 Win7 32 位和 Win7 64 位上运行它 - 没有区别 附言抱歉这个问题太长了。
【问题讨论】:
标签: windows delphi delphi-7 access-violation