评估器中的表达式非法(& Access Violation) [英] Expression illegal in evaluator (& Access Violation)

查看:26
本文介绍了评估器中的表达式非法(& Access Violation)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用类 Tbb2uc 但在调用函数 GetAddress 时获取 AV 来处理纯文本文件(加载到 StringList 中).

Im trying to process a plain text file (loaded into a StringList), by using class Tbb2uc but getting AV at calling function GetAddress.

  TArrayQuotePositions = array[1..4] of integer;

  Tbb2uc = class(TObject)
  private
    Farrayquotes: TArrayQuotePositions;
    SlInput: TStringList;
    Inputfilename: TFileName;
    SlOutput: TStringList;
    function GetQuotePositions( aLine: string ): TArrayQuotePositions;
    function GetInvoice( aLine: string ): string;
    function GetName( aLine: string ): string;
    function GetAddress( aLine: string ): string;
    function GetSwift( aLine: string ): string;
    function ProcessSl: integer;        
  public
    constructor Create;
    destructor Destroy; override;
    function OpenFile: integer;
  end;

<小时>

function Tbb2uc.GetInvoice( aLine: string ): string;
var
  quotesPos: TArrayQuotePositions;
begin
  quotesPos := GetQuotePositions( aLine );
  result := copy( aLine, quotesPos[3]+1, (quotesPos[4]-quotesPos[3])-1 );
end;

<小时>

function Tbb2uc.GetName( aLine: string ): string;  
var
  quotesPos: TArrayQuotePositions;
begin
  quotesPos := GetQuotePositions( aLine );
  result := copy( aLine, quotesPos[3]+1, (quotesPos[4]-quotesPos[3])-1 );
end;

<小时>

执行甚至没有跳转到函数中.我在调用这个函数时得到了 AV.


The execution does not even jump into the function. I get the AV at calling this function.

function Tbb2uc.GetAddress( aLine: string ): string;
var
  quotesPos: TArrayQuotePositions;
  address1: string;
  address2: string;
begin
  quotesPos := GetQuotePositions( aLine );
  address1 := copy( aLine, quotesPos[1]+1, (quotesPos[2]-quotesPos[1])-1 );
  address2 := copy( aLine, quotesPos[3]+1, (quotesPos[4]-quotesPos[3])-1 );
  result := address1 + ' ' + address2;
end;

<小时>

使用以上函数:


Using the above functions:

function Tbb2uc.ProcessSl: integer;
var
  i: integer;
  line: string;
  invoice,name,addr,swift: string;
begin
  SlInput.LoadFromFile( string(Inputfilename) );
  //
  for i := 0 to SlInput.Count -1 do begin
    if ansipos( STARTSTRING, SlInput[i]) <> 0 then begin
      invoice := GetInvoice(SlInput[i]);
      name := GetName(SlInput[i+1]);
      ////
      addr := GetAddress(SlInput[i+2]); //Access Violation
      ////
      swift := GetSwift(SlInput[i+4]);
      line := line + invoice + ';' + name + ';' + addr + ';' + swift;
    end;
    SlOutput.Add(line);
    line := '';
  end;
  SlOutput.SaveToFile( OUTPUT_FNAME );
end;

在调用 GetAddress 之前执行是可以的.在调试时,当评估 SlInput[i+2] 时,我得到评估器中的表达式非法",现在我不知道.如您所见,我只处理字符串列表的行.

The execution is ok until calling GetAddress. At debugging, when evaluate SlInput[i+2], i get 'Expression illegal in evaluator' and right now i have no idea. As you see im only processing the lines of the stringlist.

推荐答案

您访问的字符串列表越界.

You are accessing your stringlist out of bounds.

for i := 0 to SlInput.Count -1 do begin

 // ...(etc)

      addr := GetAddress(SlInput[i+2]); 

i 正在运行到列表的完整大小.你的索引比那个高两个.

i is running to the full size of the list. You are indexing two higher than that.

这篇关于评估器中的表达式非法(&amp; Access Violation)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆