* * *

Author Topic: Access violation error  (Read 707 times)

facido

  • New member
  • *
  • Posts: 15
Access violation error
« on: July 09, 2018, 12:58:35 pm »
I am receiving "Access violation" error message at line 15 on the following codes:

Code: Pascal  [Select]
  1. procedure main.GoToURLClick(Sender: TObject);
  2. Var Browser:TEvsWebBrowser;
  3.       Doc: IHTMLDocument2;
  4.       WebForm: IHTMLFormElement;
  5.       FormElements: OleVariant;
  6.       _data: variant;
  7.       url,onull:Olevariant;
  8.       ActiveXContainer:TActiveXContainer;
  9.       ovElements: OleVariant;
  10. begin
  11.  
  12.       Browser:=TEvsWebBrowser.Create(Self);
  13.  
  14.       ActiveXContainer.ComServer:=Browser.ComServer;
  15.       ActiveXContainer.Active:=true;   // "Access violation" error occurs here
  16.  
  17.       ................
  18.  
  19.  

What could be the reason for the error?

taazz

  • Hero Member
  • *****
  • Posts: 5336
Re: Access violation error
« Reply #1 on: July 09, 2018, 01:02:58 pm »
activexContainer is never created.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

facido

  • New member
  • *
  • Posts: 15
Re: Access violation error
« Reply #2 on: July 09, 2018, 04:50:07 pm »
How can you create the activexContainer?

The following code gives me runtime error:

Code: Pascal  [Select]
  1. ActivexContainer.Create(Self);
  2.  

I am a beginner in Lazarus programming.
« Last Edit: July 09, 2018, 04:56:33 pm by facido »

Munair

  • Sr. Member
  • ****
  • Posts: 347
  • Keep it simple.
    • Ditrianum
Re: Access violation error
« Reply #3 on: July 09, 2018, 05:32:51 pm »
Code: Pascal  [Select]
  1. ActiveXContainer := TActiveXContainer.Create;
You should also know why the error did not occur on line 14, even though the object wasn't created.
« Last Edit: July 09, 2018, 06:28:25 pm by Munair »
Lazarus 1.8.4; Manjaro 17.1.11; Windows 7; PC-DOS 2000

facido

  • New member
  • *
  • Posts: 15
Re: Access violation error
« Reply #4 on: July 10, 2018, 05:47:41 am »
Does anyone know why the same error didn't occur at line 14?
« Last Edit: July 10, 2018, 05:52:48 am by facido »

ASerge

  • Hero Member
  • *****
  • Posts: 900
Re: Access violation error
« Reply #5 on: July 10, 2018, 06:50:33 am »
Does anyone know why the same error didn't occur at line 14?
ActiveXContainer without Create point to random memory.
Line 14 copies a single pointer value to this random location. You're lucky you didn't lose something important because the random area is small.
Using Active := true; already requires a fully valid Self, because property Active call "write" method. Here luck has already turned away because there is too little chance that a random memory area will match the correct object.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus