评估器中的表达式非法(& Access Violation)

编程入门 行业动态 更新时间:2024-10-09 04:22:23
本文介绍了评估器中的表达式非法(& 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)

本文发布于:2023-11-28 18:50:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643561.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   器中   amp   Access   Violation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!