简体   繁体   English

如何在模块Project1.exe中修复'访问冲突,地址为00660938。 读取地址00000150。” 在印第(Delphi 10.3 Rio)

[英]How to fix 'Access violation at address 00660938 in module Project1.exe. Read of address 00000150.' in Indy (Delphi 10.3 Rio)

I'm am writing a software which will decrypt JDownloader DLC files. 我正在写一个可以解密JDownloader DLC文件的软件。 This program will send the dlc file to " http://dcrypt.it/decrypt/upload " with POST request and will get decoded links as response. 该程序将通过POST请求将dlc文件发送到“ http://dcrypt.it/decrypt/upload ”,并将获得解码后的链接作为响应。

This is my code which throws that error: 这是我的代码抛出该错误:

var
  Form1: TForm1;
    Stream: TStringStream;
    Params: TIdMultiPartFormDataStream;
    HTTP: TIdHTTP;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
  Stream := TStringStream.Create('');
  Params := TIdMultiPartFormDataStream.Create;
  Params.AddFile('File1', 'D:\3fcaa401f8f3ebe32fb93cb607ecadd01ee954ed.dlc', 'application/octet-stream');
  HTTP.Post('http://dcrypt.it/decrypt/upload', Params, Stream);
  ShowMessage(Stream.DataString);
end;

When I debug my program, Delphi IDE shows these in IdHTTP.pas: 当我调试程序时,Delphi IDE在IdHTTP.pas中显示了这些内容:

function TIdCustomHTTP.GetRequest: TIdHTTPRequest;
begin
 Result := FHTTPProto.Request; //This line is highlighted.
end;

So, what should I do in order to fix this issue? 那么,我该怎么做才能解决此问题?

You are not initializing the HTTP component. 您没有初始化HTTP组件。 Since it is a global variable it will be automatically initialized to nil . 由于它是一个全局变量,它将被自动初始化为nil

When you call HTTP.Post('http://dcrypt.it/decrypt/upload', Params, Stream); 当您调用HTTP.Post('http://dcrypt.it/decrypt/upload', Params, Stream); it will not break immediately at the place of call. 它不会在呼叫位置立即中断。 You are calling it on a nil reference, so it causes the AV as soon as it accesses some inner field or attempts to call a virtual method. 您在nil引用上调用它,因此一旦它访问某个内部字段或尝试调用虚拟方法,它就会导致AV。

You have to construct the HTTP component before you use it: 您必须先构造HTTP组件:

HTTP := TIdHTTP.Create(nil);
try
  ...
finally
  HTTP.Free;
end;

Also, good practice is that you should avoid using global variables. 另外,优良作法是应避免使用全局变量。 You can and should declare all the necessary variables as local. 您可以并且应该将所有必要的变量声明为局部变量。 And make sure that you release everything after you are done. 并确保在完成后释放所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM