EAccessViolation question

delphi package - automated exception handling
Post Reply
smot
Posts: 7
Joined: Sat Mar 26, 2005 1:21 pm

EAccessViolation question

Post by smot »

hi madshi,

Do u have a clue why I get an AV ?

exception class : EAccessViolation
exception message : Access violation at address 004DCEEF in module 'Webbrowser.exe'. Read of address C25D5E97.

main thread ($494):
004dceef Webbrowser.exe Unit1 2291 EnumProc
004dccf6 Webbrowser.exe Unit1 2265 Enum
004dce62 Webbrowser.exe Unit1 2283 EnumFrames


disassembling:
[...]
004dcedb mov eax, [ebp+8]
004dcede mov eax, [eax-4]
004dcee1 mov eax, [eax+$3f4]
004dcee7 mov eax, [eax+$218]
004dceed mov ecx, [eax]
004dceef > call dword ptr [ecx+$38]
004dcef2 xor eax, eax
004dcef4 pop edx
004dcef5 pop ecx
004dcef6 pop ecx
004dcef7 mov fs:[eax], edx
[...]

CODE:

Code: Select all

type
  TEnumFramesProc = function(AHtmlDocument: IHtmlDocument2; Data: Integer): Boolean;

function EnumFrames(AHtmlDocument: IHtmlDocument2;
  EnumFramesProc: TEnumFramesProc; Data: Integer): Boolean;

  function Enum(AHtmlDocument: IHtmlDocument2): Boolean;
  var
    OleContainer: IOleContainer;
    EnumUnknown: IEnumUnknown;
    Unknown: IUnknown;
    Fetched: LongInt;
    WebBrowser: IWebBrowser;
  begin
    Result := True;
    if not Assigned(AHtmlDocument) then
      Exit;
    Result := EnumFramesProc(AHtmlDocument, Data);
    if not Result then
      Exit;

    if not Supports(AHtmlDocument, IOleContainer, OleContainer) then
      Exit;
    if Failed(OleContainer.EnumObjects(OLECONTF_EMBEDDINGS, EnumUnknown)) then
      Exit;
    while (EnumUnknown.Next(1, Unknown, @Fetched) = S_OK) do
      if Supports(Unknown, IWebBrowser, WebBrowser) then
      begin
        Result := Enum(WebBrowser.Document as IHtmlDocument2);
        if not Result then
          Exit;
      end;
  end;
begin
  Result := Enum(AHtmlDocument);
end;


procedure TfrmMyBrowser.Button1Click(Sender: TObject);

  function EnumProc(AHtmlDocument: IHtmlDocument2; Data: Integer): Boolean;
  begin
    ListBox1.Items.Add(AHtmlDocument.url);
  end;
  
begin
  EnumFrames(WebBrowser1.ControlInterface.Document as IHtmlDocument2,
    @EnumProc, Integer(Self));
end;

Edit:

Error occurs here:

ListBox1.Items.Add(AHtmlDocument.url);

On the other hand, ShowMessage(AHtmlDocument.url)
doesn't show an error
smot
Posts: 7
Joined: Sat Mar 26, 2005 1:21 pm

Post by smot »

Naver mind, I've solved the problem.

Code: Select all

frmMyBrowser.ListBox1.Items.Add(AHtmlDocument.url); 
Post Reply