Autor Beitrag
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 26.03.05 14:38 
Hi!

Hat jemand ne Ahnung, warum's mir eine AV bei folgendem Code gibt?


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
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;
var
  s: string;
begin
  s :=  AHtmlDocument.url;
  Memo1.lines.Add(s); /// <--------- AV!
  // wenn ich's mit ShowMessage(s) anzeige, gibt's keine AV!!???
end;
  
begin
  EnumFrames(WebBrowser1.ControlInterface.Document as IHtmlDocument2,
    @EnumProc, Integer(Self));
end;



Zitat:
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
[...]


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Jailbird
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 127

Windows XP Pro SP2
Delphi 7 Professional
BeitragVerfasst: Sa 26.03.05 14:46 
wenn's bei ShowMessage keine AV gibt, dann probier mal das hier

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
begin
  s :=  AHtmlDocument.url;
  Memo1.lines.Add(string(s)); /// <--------- AV!
  // wenn ich's mit ShowMessage(s) anzeige, gibt's keine AV!!???
end;
toms Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 26.03.05 14:57 
Memo1.lines.Add(string(s)); gibt auch eine AV.
Selbst Memo1.lines.Add('');

Hab's aber inzwischen so geloest:

ausblenden Quelltext
1:
 FormName.Memo1.lines.Add(s);					
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Sa 26.03.05 17:23 
user profile icontoms hat folgendes geschrieben:
Memo1.lines.Add(string(s)); gibt auch eine AV.
Selbst Memo1.lines.Add('');

Ist ja auch klar, da es keinen gültigen Self-Parameter gibt - die Prozedur wird ja aus EnumFrames heraus aufgerufen. Aber du übergibst Self ja eh als Data, also warum nicht so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TfrmMyBrowser.Button1Click(Sender: TObject);

function EnumProc(AHtmlDocument: IHtmlDocument2; Data: Integer): Boolean;
var
  s: string;
begin
  s :=  AHtmlDocument.url;
  TfrmMyBrowser(Data).Memo1.lines.Add(s);
end;
  
begin
  EnumFrames(WebBrowser1.ControlInterface.Document as IHtmlDocument2,
    @EnumProc, Integer(Self));
end;

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!