OSDN Git Service

TWebBrowserの参照カウントが正しくなるように修正
authoreggcake <eggcake>
Sun, 13 Apr 2008 04:20:24 +0000 (04:20 +0000)
committereggcake <eggcake>
Sun, 13 Apr 2008 04:20:24 +0000 (04:20 +0000)
BrowserRecord.pas
Editor.pas
Giko.pas
GikoDataModule.pas
GikoSystem.pas
HTMLCreate.pas
MoveHistoryItem.pas
Option.pas
ResPopupBrowser.pas
gikoNavi.todo

index 9011857..683e0bd 100644 (file)
@@ -62,18 +62,25 @@ end;
 // *************************************************************************
 destructor     TBrowserRecord.Destroy;
 var
-       doc :OleVariant;
+       doc :IHTMLDocument2;
 begin
        if Self.FEvent <> nil then
                Self.FEvent.Free;
+
        if Self.FBrowser <> nil then begin
                if Self.Thread <> nil then begin
                        //\83^\83u\82Ì\95\9c\8c³\82Å\95\9c\8c³\82³\82ê\82½\83X\83\8c\82Í\81A\95`\89æ\82³\82ê\82Ä\82¢\82È\82¢\82Æ\82«\82ª\82 \82é\82Ì\82Å
                        //\82»\82Ì\82Æ\82«\82Ì\83X\83N\83\8d\81[\83\8b\97Ê\82ð\95Û\91\82µ\82Ä\82µ\82Ü\82¤\82Æ\83g\83b\83v\82É\96ß\82Á\82Ä\82µ\82Ü\82¤\81B
-                       if Self.FBrowser.OleObject.Document.documentElement.innerText <> '' then begin
-                               doc := Idispatch( olevariant(Self.FBrowser.ControlInterface).Document) as IHTMLDocument2;
-                               Self.Thread.ScrollTop := doc.Body.ScrollTop;
-                       end;
+
+            try
+                doc := Self.FBrowser.ControlInterface.Document as IHTMLDocument2;
+                if Assigned(doc) then begin
+                    if (doc as IHTMLDocument3).documentElement.innerText <> '' then begin
+                        Self.Thread.ScrollTop := (doc.body as IHTMLElement2).scrollTop;
+                           end;
+                end;
+            except
+            end;
                end;
                ShowWindow(Self.FBrowser.Handle, SW_HIDE);
        end;
@@ -86,50 +93,54 @@ procedure TBrowserRecord.Move(const AName: string);
 var
        top: Integer;
        item: OleVariant;
+    doc : OleVariant;
 begin
        //\83u\83\89\83E\83U\82ª\95t\82¢\82Ä\82é\82Æ\82«\82¾\82¯\8f\88\97\9d\82·\82é
-       if (Self.Browser <> nil) then begin
-               //\83u\83\89\83E\83U\82ª\83f\81[\83^\82Ì\93Ç\82Ý\8d\9e\82Ý\92\86\82Ì\8e\9e\82Í\93Ç\82Ý\8d\9e\82Ý\82ð\91Ò\82Â
-               while (Self.Browser.ReadyState <> READYSTATE_COMPLETE) and
-                                       (Self.Browser.ReadyState <> READYSTATE_INTERACTIVE) do begin
-                       Sleep(1);
-                       Application.ProcessMessages;
-               end;
+    if not Assigned(Self.Browser) then
+        Exit;
 
-               try
-                       top := 0;
-                       item := OleVariant( Self.Browser.Document as IHTMLDocument2)
-                                       .anchors.item(OleVariant(AName));
-                       item.focus();
-                       repeat
-                               top := top + item.offsetTop;
-                               item := item.offsetParent;
-                       until AnsiCompareText(item.tagName, 'body' ) = 0;
-                       OleVariant(Self.Browser.Document as IHTMLDocument2).body.scrollTop := top;
-               except
-               end;
+       //\83u\83\89\83E\83U\82ª\83f\81[\83^\82Ì\93Ç\82Ý\8d\9e\82Ý\92\86\82Ì\8e\9e\82Í\93Ç\82Ý\8d\9e\82Ý\82ð\91Ò\82Â
+       while (Self.Browser.ReadyState <> READYSTATE_COMPLETE) and
+                       (Self.Browser.ReadyState <> READYSTATE_INTERACTIVE) do begin
+               Sleep(1);
+               Application.ProcessMessages;
+       end;
+
+       try
+        doc := Self.Browser.OleObject.Document;
+               top := 0;
+               item := doc.anchors.item(OleVariant(AName));
+               item.focus();
+               repeat
+                       top := top + item.offsetTop;
+               item := item.offsetParent;
+               until AnsiCompareText(item.tagName, 'body' ) = 0;
+               doc.body.scrollTop := top;
+       except
        end;
 end;
 // *************************************************************************
 //! \83u\83\89\83E\83U\82ð\83X\83N\83\8d\81[\83\8b\82³\82¹\82é
 // *************************************************************************
 procedure TBrowserRecord.Move(scroll: Integer);
+var
+    doc: IHTMLDocument2;
 begin
        //\83u\83\89\83E\83U\82ª\95t\82¢\82Ä\82é\82Æ\82«\82¾\82¯\8f\88\97\9d\82·\82é
-       if (Self.Browser <> nil) then begin
-               //\83u\83\89\83E\83U\82ª\83f\81[\83^\82Ì\93Ç\82Ý\8d\9e\82Ý\92\86\82Ì\8e\9e\82Í\93Ç\82Ý\8d\9e\82Ý\82ð\91Ò\82Â
-               while (Self.Browser.ReadyState <> READYSTATE_COMPLETE) and
-                                       (Self.Browser.ReadyState <> READYSTATE_INTERACTIVE) do begin
-                       Sleep(1);
-                       Application.ProcessMessages;
-               end;
+    if not Assigned(Self.Browser) then
+        Exit;
 
-               try
-                       OleVariant(Self.Browser.Document as IHTMLDocument2).body.scrollTop
-                := OleVariant(Self.Browser.Document as IHTMLDocument2).body.scrollTop
-                    + scroll;
-               except
-               end;
+       //\83u\83\89\83E\83U\82ª\83f\81[\83^\82Ì\93Ç\82Ý\8d\9e\82Ý\92\86\82Ì\8e\9e\82Í\93Ç\82Ý\8d\9e\82Ý\82ð\91Ò\82Â
+       while (Self.Browser.ReadyState <> READYSTATE_COMPLETE) and
+                               (Self.Browser.ReadyState <> READYSTATE_INTERACTIVE) do begin
+               Sleep(1);
+               Application.ProcessMessages;
+       end;
+
+       try
+        doc := Self.Browser.ControlInterface.Document as IHTMLDocument2;
+               (doc.body as IHTMLElement2).scrollTop := (doc.body as IHTMLElement2).scrollTop + scroll;
+       except
        end;
 end;
 
@@ -140,37 +151,38 @@ const
        HIDDEN = 'hidden';
 var
        firstElement: IHTMLElement;
-       document: IHTMLDocument2;
-       docAll: IHTMLElementCollection;
-       doc : Variant;
+       doc : IHTMLDocument2;
        nCSS : string;
 begin
-       if Self.Browser <> nil then begin
-               try
-                       document := Self.Browser.Document as IHTMLDocument2;
-
-                       if Assigned(document) then begin
-                               docAll := document.all;
-                               firstElement := docAll.item('idSearch', 0) as IHTMLElement;
-                               if (Assigned(firstElement)) then begin
-                                       if Length(Abody) > 0 then begin
-                                               doc := Idispatch( olevariant(Self.Browser.ControlInterface).Document) as IHTMLDocument2;
-                                               nCSS := '<p id="idSearch" style="position:absolute;top:' + IntToStr(doc.Body.ScrollTop + 10) + 'px;right:5px;' //
-                                                       + 'background-color:window; border:outset 1px infobackground; z-index:10; overflow-y:auto; border-top:none">'
-                                                       + Abody + '</p>';
-                                               firstElement.outerHTML := nCSS;
-                                               firstElement.style.visibility := 'visible';
-                                       end else begin
-                                               firstElement.outerHTML := OUTER_HTML;
-                                               firstElement.style.visibility := HIDDEN;
-                                       end;
-                               end else if (Assigned(firstElement)) then begin
-                                       firstElement.outerHTML := OUTER_HTML;
-                                       firstElement.style.visibility := HIDDEN;
-                               end;
-                       end;
-               except
-               end;
+    if not Assigned(Self.Browser) then
+        Exit;
+
+       try
+               doc := Self.Browser.ControlInterface.Document as IHTMLDocument2;
+               if not Assigned(doc) then
+            Exit;
+
+               firstElement := doc.all.item('idSearch', 0) as IHTMLElement;
+               if not Assigned(firstElement) then
+            Exit;
+
+        try
+               if Length(Abody) > 0 then begin
+                       nCSS := '<p id="idSearch" style="position:absolute;top:' + IntToStr((doc.body as IHTMLElement2).ScrollTop + 10) + 'px;right:5px;' //
+                               + 'background-color:window; border:outset 1px infobackground; z-index:10; overflow-y:auto; border-top:none">'
+                                   + Abody + '</p>';
+                       firstElement.outerHTML := nCSS;
+                       firstElement.style.visibility := 'visible';
+                   end else begin
+                           firstElement.outerHTML := OUTER_HTML;
+                       firstElement.style.visibility := HIDDEN;
+               end;
+           except
+                   firstElement.outerHTML := OUTER_HTML;
+                       firstElement.style.visibility := HIDDEN;
+       end;
+
+       except
        end;
 end;
 {
@@ -185,8 +197,6 @@ var
        vaIn, vaOut: OleVariant;
 begin
        if Assigned(Self.Browser) then begin
-               vaIn  := 0;
-               vaOut := 0;
                try
                        CmdTarget := Self.Browser.ControlInterface.Document as IOleCommandTarget;
                        if Assigned(CmdTarget) then begin
index 6cdd3f2..54e612b 100644 (file)
@@ -698,10 +698,10 @@ end;
 
 procedure TEditorForm.SetContent(Content: string; ABrowser: TWebBrowser);
 var
-       doc: Variant;
+       doc: OleVariant;
 begin
-       if ABrowser.Document <> nil then begin
-               doc := Idispatch( olevariant(ABrowser.ControlInterface).Document) as IHTMLDocument2;
+       if ABrowser.ControlInterface.Document <> nil then begin
+               doc := ABrowser.OleObject.Document;
                doc.Clear;
                doc.open;
                doc.charset := 'Shift_JIS';
@@ -1799,34 +1799,38 @@ end;
 
 procedure TEditorForm.ShowBoardHead(ABoard: TBoard; AMemo: TMemo);
 var
-        wDoc, WTex, le: OLEVariant;
-begin
-               //\8eQ\8dl\8c³
-               //http://www.campus.ne.jp/~ishigami/CREATION/TECHNIC/WEBAP-2.htm
-               WebBrowser1.Navigate(ABoard.GETHEADTXTFileName,le,le,le,le);
-               //\83\8c\83^\83\8a\83\93\83O\82ª\92x\82·\82¬\82ÄTXT\82É\88Ú\82¹\82È\82¢\81B\82Ê\82é\82Ûorz
-               //\89º\82Ì\82æ\82¤\82É\82¿\82á\82ñ\82Æ\93Ç\82Ý\8d\9e\82Ý\82ª\8fI\82í\82Á\82Ä\82¢\82é\82©\81A\83`\83F\83b\83N\82·\82ê\82Î\82¢\82¢\82ñ\82¾\82æ\81B
-               //\82±\82ê\82Å\82¢\82¯\82Ü\82µ\82½\81B\82 \82è\82ª\82Æ\82¤\82²\82´\82¢\82Ü\82µ\82½\81B
-               while (WebBrowser1.ReadyState <> READYSTATE_COMPLETE) and
-                               (WebBrowser1.ReadyState <> READYSTATE_INTERACTIVE) do begin
-                       Application.ProcessMessages;
-               end;
-               wDoc := WebBrowser1.Document;
-               wTex := wDoc.body.createTextRange;
-               LocalEdit.Text := wTex.text;
+    range: OleVariant;
+begin
+       //\8eQ\8dl\8c³
+       //http://www.campus.ne.jp/~ishigami/CREATION/TECHNIC/WEBAP-2.htm
+       WebBrowser1.Navigate(ABoard.GETHEADTXTFileName);
+       //\83\8c\83^\83\8a\83\93\83O\82ª\92x\82·\82¬\82ÄTXT\82É\88Ú\82¹\82È\82¢\81B\82Ê\82é\82Ûorz
+       //\89º\82Ì\82æ\82¤\82É\82¿\82á\82ñ\82Æ\93Ç\82Ý\8d\9e\82Ý\82ª\8fI\82í\82Á\82Ä\82¢\82é\82©\81A\83`\83F\83b\83N\82·\82ê\82Î\82¢\82¢\82ñ\82¾\82æ\81B
+       //\82±\82ê\82Å\82¢\82¯\82Ü\82µ\82½\81B\82 \82è\82ª\82Æ\82¤\82²\82´\82¢\82Ü\82µ\82½\81B
+       while (WebBrowser1.ReadyState <> READYSTATE_COMPLETE) and
+                       (WebBrowser1.ReadyState <> READYSTATE_INTERACTIVE) do begin
+               Application.ProcessMessages;
+       end;
+
+    try
+       range := WebBrowser1.OleObject.Document.body.createTextRange;
+           LocalEdit.Text := range.text;
+    except
+    end;
 end;
 
 procedure TEditorForm.LocalRuleBrowseClick(Sender: TObject);
 var
-        URL: String;
-        ABoard: TBoard;
+    URL: String;
+    ABoard: TBoard;
 begin
     ABoard := GetBoard;
 
-       if ABoard = nil then Exit;
+       if ABoard = nil
+        then Exit;
 
-               URL := ABoard.GETHEADTXTFileName;
-               GikoSys.OpenBrowser(URL, gbtAuto);
+    URL := ABoard.GETHEADTXTFileName;
+    GikoSys.OpenBrowser(URL, gbtAuto);
 end;
 
 procedure TEditorForm.SaveNameMailActionExecute(Sender: TObject);
index 07de719..037d505 100644 (file)
--- a/Giko.pas
+++ b/Giko.pas
@@ -903,7 +903,7 @@ begin
 {$ENDIF}
 //try
        Sort.SetSortDate(Now());
-       
+
        FTreeType := gttNone;
        // \8bN\93®\8e\9e\82É\95Û\91\82³\82ê\82Ä\82µ\82Ü\82¤\91Î\8dô
        FStartUp := true;
@@ -1545,6 +1545,7 @@ var
        i                               : Integer;
        wp                      : TWindowPlacement;
        tmpBool : Boolean;
+    doc:IHTMLDocument2;
 begin
        // \83}\83E\83X\83W\83F\83X\83`\83\83\81[\8aJ\95ú
        try
@@ -1630,6 +1631,11 @@ begin
        end;
        try
                for i := FBrowsers.Count - 1 downto 0 do begin
+            GikoSys.ShowRefCount('browser' + IntToStr(i), TWebBrowser(FBrowsers[i]).ControlInterface);
+            GikoSys.ShowRefCount('document' + IntToStr(i), TWebBrowser(FBrowsers[i]).ControlInterface.Document);
+               end;
+
+               for i := FBrowsers.Count - 1 downto 0 do begin
                        TWebBrowser(FBrowsers[i]).Free;
                end;
                FBrowsers.Clear;
@@ -1909,31 +1915,41 @@ var
        e: IHTMLElement;
        Ext: string;
        PathRec: TPathRec;
-  Text2: string;
+    Text2: string;
     cResPopup: TResPopupBrowser;
+    senderBrowser :TWebBrowser;
+    doc: IHTMLDocument2;
 begin
-       // \83M\83R\83i\83r\82Í\83\8c\83X\83A\83\93\83J\81[\82ª about:blank.. \82Å\8en\82Ü\82é\82±\82Æ\82ð\8aú\91Ò\82µ\82Ä\82¢\82é\82ª
-  // IE 7 \82Å\82Í about:blank.. \82Å\82Í\82È\82­ about:.. \82É\82È\82é\82Ì\82Å\81A\92u\8a·\82·\82é(\93\8a\82°\82â\82è)
-       if Pos('about:..', Text) = 1 then
-       Text2 := 'about:blank..' + Copy( Text, Length('about:..')+1, Length(Text) )
-  else
-       Text2 := Text;
+    // \83M\83R\83i\83r\82Í\83\8c\83X\83A\83\93\83J\81[\82ª about:blank.. \82Å\8en\82Ü\82é\82±\82Æ\82ð\8aú\91Ò\82µ\82Ä\82¢\82é\82ª
+    // IE 7 \82Å\82Í about:blank.. \82Å\82Í\82È\82­ about:.. \82É\82È\82é\82Ì\82Å\81A\92u\8a·\82·\82é(\93\8a\82°\82â\82è)
+    if Pos('about:..', Text) = 1 then
+        Text2 := 'about:blank..' + Copy( Text, Length('about:..')+1, Length(Text) )
+    else
+        Text2 := Text;
+
        if not( TObject(Sender) is TWebBrowser )then
                Exit;
+
+    senderBrowser := TWebBrowser(Sender);
+    doc := senderBrowser.ControlInterface.Document as IHTMLDocument2;
+
        try
                try
-                       if (TWebBrowser(Sender) <> nil) and (not TWebBrowser(Sender).Busy) and (Assigned(TWebBrowser(Sender).Document)) then begin
-                               if LowerCase(OleVariant(IHTMLDocument2(TWebBrowser(Sender).Document)).charset) <> 'shift_jis' then begin
-                                       OleVariant(IHTMLDocument2(TWebBrowser(Sender).Document)).charset := 'shift_jis';
+                       if ((not senderBrowser.Busy) and Assigned(doc)) then begin
+                               if LowerCase(doc.charset) <> 'shift_jis' then begin
+                                       doc.charset := 'shift_jis';
                                end;
                        end;
                except
                end;
        finally
        end;
+
        if PreviewTimer.Enabled then
                PreviewTimer.Enabled := False;
+
        Application.CancelHint;
+
        try
                if GetActiveContent <> nil then
                        ActiveFileName := ChangeFileExt(ExtractFileName(GetActiveContent.FileName), '')
@@ -1943,6 +1959,7 @@ begin
                FActiveContent := nil;
                Exit;
        end;
+
     // \91O\89ñ\82Æ\93¯\82\8fê\8d\87\8fI\97¹
     if (StatusBar.Panels[1].Text = Text2) then begin
         if Text2 = '' then begin
@@ -2014,9 +2031,9 @@ begin
                        s := StringReplace(Text2, 'mailto:', '', [rfIgnoreCase]);
                        //\83M\83R\83i\83r\83X\83\8c \83p\81[\83g3\82Ì466\8e\81\82É\8a´\8eÓ
                        GetCursorPos(p);
-                       p.x := p.x - TWebBrowser(Sender).ClientOrigin.x;
-                       p.y := p.y - TWebBrowser(Sender).ClientOrigin.y;
-                       e := IHTMLDocument2(TWebBrowser(Sender).Document).elementFromPoint(p.x, p.y);
+                       p.x := p.x - senderBrowser.ClientOrigin.x;
+                       p.y := p.y - senderBrowser.ClientOrigin.y;
+                       e := doc.elementFromPoint(p.x, p.y);
                        if (Assigned(e)) then begin
                 CreateResPopupBrowser;
 
@@ -2806,7 +2823,7 @@ var
        BBSID: string;
        FileName: string;
        sTitle: string;
-       doc: Variant;
+       doc: OleVariant;
        s: string;
        idx: Integer;
        ThreadItem: TThreadItem;
@@ -2820,14 +2837,14 @@ begin
         (FActiveContent <> nil) and
                (FActiveContent.Thread <> Thread.Thread) and
                (FActiveContent.Browser <> nil) and
-               (Assigned(FActiveContent.Browser.Document)) then begin
-               try
-               try
-                       FActiveContent.Thread.ScrollTop := OleVariant(IHTMLDocument2(FActiveContent.Browser.Document).Body).ScrollTop;
-               except
-                       on E: Exception do
-                               MsgBox(Handle, E.Message, 'SetContent[<-ScrollTop]', 0);
-               end;
+               (Assigned(FActiveContent.Browser.ControlInterface.Document)) then begin
+        try
+            try
+                FActiveContent.Thread.ScrollTop := FActiveContent.Browser.OleObject.Document.Body.ScrollTop;
+            except
+            on E: Exception do
+                MsgBox(Handle, E.Message, 'SetContent[<-ScrollTop]', 0);
+        end;
                finally
                end;
        end;
@@ -2879,7 +2896,7 @@ begin
                                ShowWindow(FActiveContent.Browser.Handle, SW_HIDE);
                end;
                ShowWindow(Thread.Browser.Handle, SW_SHOW);
-               if (not Assigned(Thread.Browser.Document)) then begin
+               if (not Assigned(Thread.Browser.ControlInterface.Document)) then begin
                        Thread.Browser.Navigate('about:blank');
                end;
                while (Thread.Browser.ReadyState <> READYSTATE_COMPLETE) and
@@ -2917,7 +2934,7 @@ begin
                        try
                                Thread.Browser.BringToFront;
                                s := '<HTML><BODY><CENTER>\82±\82Ì\83X\83\8c\83b\83h\82Í\8eæ\93¾\82µ\82Ä\82¢\82Ü\82¹\82ñ</CENTER></BODY></HTML>';
-                               doc := Idispatch( olevariant(Thread.Browser.ControlInterface).Document) as IHTMLDocument2;
+                               doc := Thread.Browser.OleObject.Document;
                                doc.open;
                                doc.charset := 'Shift_JIS';
                                doc.Write(s);
@@ -3648,29 +3665,32 @@ begin
 end;
 procedure TGikoForm.DeleteTab(index, selectIndex: Integer);
 var
-    doc: Variant;
+    browserRec : TBrowserRecord;
+    doc: OleVariant;
     j: Integer;
 begin
+    browserRec := TBrowserRecord(BrowserTab.Tabs.Objects[index]);
     try
-        if TBrowserRecord(BrowserTab.Tabs.Objects[index]).Browser <> nil then begin
-            doc := TBrowserRecord(BrowserTab.Tabs.Objects[index]).Browser.Document;
-            TBrowserRecord(BrowserTab.Tabs.Objects[index]).Thread.ScrollTop := doc.Body.ScrollTop;
+        if browserRec.Browser <> nil then begin
+            doc := browserRec.Browser.OleObject.Document;
+            browserRec.Thread.ScrollTop := doc.Body.ScrollTop;
         end;
     except
-        TBrowserRecord(BrowserTab.Tabs.Objects[index]).Thread.ScrollTop := 0;
+        browserRec.Thread.ScrollTop := 0;
     end;
-    if(FActiveContent = TBrowserRecord(BrowserTab.Tabs.Objects[index])) then
+
+    if(FActiveContent = browserRec) then
         FActiveContent := nil;
-    if TBrowserRecord(BrowserTab.Tabs.Objects[index]).Browser <> nil then begin
-        j := FBrowsers.IndexOf(TBrowserRecord(BrowserTab.Tabs.Objects[index]).Browser);
+    if browserRec.Browser <> nil then begin
+        j := FBrowsers.IndexOf(browserRec.Browser);
         if j <> -1 then
             FBrowsers.Move(j, BROWSER_COUNT - 1);
     end;
+
     BrowserTab.Tabs.BeginUpdate;
     try
-        GikoSys.Setting.LastCloseTabURL :=
-            TBrowserRecord(BrowserTab.Tabs.Objects[index]).Thread.URL;
-        TBrowserRecord(BrowserTab.Tabs.Objects[index]).Free;
+        GikoSys.Setting.LastCloseTabURL := browserRec.Thread.URL;
+        browserRec.Free;
         if ( BrowserTab.Tabs.Count - 1 = index ) and
             ( BrowserTab.TabRect(index).Left
                 <= BrowserTab.DisplayRect.Left ) then begin
@@ -3691,6 +3711,7 @@ begin
     if BrowserTab.Tabs.Count = 0 then begin
         BrowserNullTab.Thread := nil;
     end;
+
     if(BrowserTab.TabIndex <> -1) and
         ( TBrowserRecord(BrowserTab.Tabs.Objects[BrowserTab.TabIndex]).Browser = nil) then begin
         // \88ê\94Ô\8cÃ\82¢\83u\83\89\83E\83U\82ð\8aJ\95ú\82·\82é
@@ -3843,90 +3864,103 @@ var
     BNum, BRes: string;
     threadItem: TThreadItem;
     aElement : IHTMLElement;
+    senderBrowser : TWebBrowser;
+    doc : IHTMLDocument2;
 begin
 {$IFDEF DEBUG}
        Writeln(IntToStr(Integer(ppDisp)));
 {$ENDIF}
        Cancel := True;
-    aElement := IHTMLDocument2(TWebBrowser(Sender).Document).activeElement;
-       if ( aElement <> nil) then begin
-               Text := aElement.Get_outerText;
-               Html := aElement.Get_outerHTML;
-               if(AnsiPos('>>', Text) = 1) or (AnsiPos('>', Text) = 1)
-                       or (AnsiPos('\81\84\81\84', Text) = 1) or (AnsiPos('\81\84', Text) = 1) then begin
-                       if GikoSys.Setting.ResAnchorJamp then begin
-
-                               Text := ZenToHan(Trim(Text));
-
-                               if(AnsiPos('>>', Text) = 1) then begin
-                                       //Text := Copy(Text, 3, Length(Text) - 2);
-                                       Delete(Text, 1, 2);
-                               end else begin
-                                       //Text := Copy(Text, 2, Length(Text) - 1);
-                                       Delete(Text, 1, 1);
-                               end;
 
-                               if AnsiPos('-', Text) <> 0 then begin
-                                       wkIntSt := StrToIntDef(Copy(Text, 1, AnsiPos('-', Text) - 1), 0);
-                                       Text := Copy(Text, AnsiPos('-', Text) + 1, Length(Text));
-                                       wkIntTo := StrToIntDef(Text, 0);
-                                       if wkIntTo < wkIntSt then
-                                               wkIntSt := wkIntTo;
-                               end else begin
-                                       wkIntSt := StrToIntDef(Text, 0);
-                               end;
+       if not( TObject(Sender) is TWebBrowser )then
+               Exit;
 
-                               if wkIntSt <> 0 then begin
-                       FActiveContent.IDAnchorPopup('');
-                    MoveHisotryManager.pushItem(FActiveContent);
-                    if (Sender is TResPopupBrowser) then begin
-                        TResPopupBrowser(Sender).ChildClear;
-                        OpenThreadItem(
-                            GetActiveContent(true),
-                            GetActiveContent(true).URL + '&st=' +
-                                 IntToStr(wkIntSt) + '&to=' + IntToStr(wkIntSt));
-                    end else begin
-                                       BrowserMovement(IntToStr(wkIntSt));
-                    end;
-                end;
+    senderBrowser := TWebBrowser(Sender);
+    doc := senderBrowser.ControlInterface.Document as IHTMLDocument2;
+       if not Assigned(doc) then
+               Exit;
+
+       aElement := doc.activeElement;
+       if not Assigned(aElement) then
+               Exit;
+
+       Text := aElement.Get_outerText;
+       Html := aElement.Get_outerHTML;
+
+       if(AnsiPos('>>', Text) = 1) or (AnsiPos('>', Text) = 1)
+               or (AnsiPos('\81\84\81\84', Text) = 1) or (AnsiPos('\81\84', Text) = 1) then begin
+               if GikoSys.Setting.ResAnchorJamp then begin
+
+                       Text := ZenToHan(Trim(Text));
+
+                       if(AnsiPos('>>', Text) = 1) then begin
+                               //Text := Copy(Text, 3, Length(Text) - 2);
+                               Delete(Text, 1, 2);
+                       end else begin
+                               //Text := Copy(Text, 2, Length(Text) - 1);
+                               Delete(Text, 1, 1);
                        end;
-               end else begin
-            ////'http://be.2ch.net/test/p.php?i='+id+'&u=d:'+bas+num
-
-                       URL := GikoSys.GetHRefText(Html);
-                       URL := GikoSys.HTMLDecode(URL);
-            if AnsiPos('BE:', URL) = 1 then begin
-                               BNum := Copy(URL, 4, AnsiPos('/', URL) - 4);
-                               BRes := Copy(URL, AnsiPos('/', URL) + 1,  Length(URL));
-                threadItem := FActiveContent.Thread;
-                if threadItem = nil then Exit;
-                URL := BE_PHP_URL + BNum + '&u=d'
-                       + CustomStringReplace(threadItem.URL, 'l50', '') + BRes;
-            end;
 
-                       if( AnsiPos('http://', URL) = 1) or (AnsiPos('https://', URL) = 1) or
-                               ( AnsiPos('ftp://', URL) = 1) then begin
-                               //\83A\83h\83\8c\83X\83o\81[\82Ì\97\9a\97ð
-                               if GikoSys.Setting.LinkAddAddressBar then begin
-                                       idx := AddressComboBox.Items.IndexOf(URL);
-                                       if idx = -1 then begin
-                                               AddressComboBox.Items.Insert(0, URL);
-                                               if AddressComboBox.Items.Count > GikoSys.Setting.AddressHistoryCount then
-                                                       AddressComboBox.Items.Delete(AddressComboBox.Items.Count - 1);
-                                       end else begin
-                                               AddressComboBox.Items.Delete(idx);
-                                               AddressComboBox.Items.Insert(0, URL);
-                                       end;
-                               end;
+                       if AnsiPos('-', Text) <> 0 then begin
+                               wkIntSt := StrToIntDef(Copy(Text, 1, AnsiPos('-', Text) - 1), 0);
+                               Text := Copy(Text, AnsiPos('-', Text) + 1, Length(Text));
+                               wkIntTo := StrToIntDef(Text, 0);
+                               if wkIntTo < wkIntSt then
+                                       wkIntSt := wkIntTo;
+                       end else begin
+                               wkIntSt := StrToIntDef(Text, 0);
+                       end;
+
+                       if wkIntSt <> 0 then begin
+               FActiveContent.IDAnchorPopup('');
+                MoveHisotryManager.pushItem(FActiveContent);
                 if (Sender is TResPopupBrowser) then begin
-                    TResPopupBrowser(Sender).ChildClear
+                    TResPopupBrowser(Sender).ChildClear;
+                    OpenThreadItem(
+                        GetActiveContent(true),
+                        GetActiveContent(true).URL + '&st=' +
+                             IntToStr(wkIntSt) + '&to=' + IntToStr(wkIntSt));
+                end else begin
+                                       BrowserMovement(IntToStr(wkIntSt));
                 end;
+            end;
+               end;
+       end else begin
+        ////'http://be.2ch.net/test/p.php?i='+id+'&u=d:'+bas+num
+
+               URL := GikoSys.GetHRefText(Html);
+               URL := GikoSys.HTMLDecode(URL);
+        if AnsiPos('BE:', URL) = 1 then begin
+                       BNum := Copy(URL, 4, AnsiPos('/', URL) - 4);
+                       BRes := Copy(URL, AnsiPos('/', URL) + 1,  Length(URL));
+            threadItem := FActiveContent.Thread;
+            if threadItem = nil then Exit;
+            URL := BE_PHP_URL + BNum + '&u=d'
+               + CustomStringReplace(threadItem.URL, 'l50', '') + BRes;
+        end;
 
-                MoveHisotryManager.pushItem(FActiveContent);
-                               MoveToURL( URL );
+               if( AnsiPos('http://', URL) = 1) or (AnsiPos('https://', URL) = 1) or
+                       ( AnsiPos('ftp://', URL) = 1) then begin
+                       //\83A\83h\83\8c\83X\83o\81[\82Ì\97\9a\97ð
+                       if GikoSys.Setting.LinkAddAddressBar then begin
+                               idx := AddressComboBox.Items.IndexOf(URL);
+                               if idx = -1 then begin
+                                       AddressComboBox.Items.Insert(0, URL);
+                                       if AddressComboBox.Items.Count > GikoSys.Setting.AddressHistoryCount then
+                                               AddressComboBox.Items.Delete(AddressComboBox.Items.Count - 1);
+                               end else begin
+                                       AddressComboBox.Items.Delete(idx);
+                                       AddressComboBox.Items.Insert(0, URL);
+                               end;
                        end;
+            if (Sender is TResPopupBrowser) then begin
+                TResPopupBrowser(Sender).ChildClear
+            end;
+
+            MoveHisotryManager.pushItem(FActiveContent);
+                       MoveToURL( URL );
                end;
-    end;
+       end;
 
 end;
 
@@ -4161,10 +4195,9 @@ end;
 procedure TGikoForm.BrowserDocumentComplete(Sender: TObject;
        const pDisp: IDispatch; var URL: OleVariant);
 var
-       FDispHtmlDocument: DispHTMLDocument;
        BrowserRecord :TBrowserRecord;
        i :Integer;
-       doc                                     : Variant;
+       doc     : IHTMLDocument2;
        threadItem      : TThreadItem;
 begin
        if TObject(Sender) is TWebBrowser then begin
@@ -4179,17 +4212,15 @@ begin
                        if BrowserRecord <> nil then begin
                                if BrowserRecord.Event <> nil then
                                        BrowserRecord.Event.Free;
-                               FDispHtmlDocument := Idispatch(OleVariant(BrowserRecord.Browser.ControlInterface).Document) as DispHTMLDocument;
-                               BrowserRecord.Event := THTMLDocumentEventSink.Create(Self, FDispHtmlDocument, HTMLDocumentEvents2);
+                               BrowserRecord.Event := THTMLDocumentEventSink.Create(Self, BrowserRecord.Browser.ControlInterface.Document, HTMLDocumentEvents2);
                                BrowserRecord.Event.OnContextMenu := OnDocumentContextMenu;
                                BrowserRecord.Event.OnClick := WebBrowserClick;  //\92Ç\89Á\82µ\82½OnClick\83C\83x\83\93\83g
                        end;
                end else begin
                        if GetActiveContent <> nil then begin
-                               FDispHtmlDocument := Idispatch(OleVariant(Browser.ControlInterface).Document) as DispHTMLDocument;
                                if FEvent <> nil then
                                        FEvent.Free;
-                               FEvent := THTMLDocumentEventSink.Create(Self, FDispHtmlDocument, HTMLDocumentEvents2);
+                               FEvent := THTMLDocumentEventSink.Create(Self, Browser.ControlInterface.Document, HTMLDocumentEvents2);
                                FEvent.OnContextMenu := OnDocumentContextMenu;
                                FEvent.OnClick := WebBrowserClick;  //\92Ç\89Á\82µ\82½OnClick\83C\83x\83\93\83g
                        end else begin
@@ -4227,8 +4258,8 @@ begin
                                RefreshListView(threadItem);
                        end else if threadItem.ScrollTop <> 0 then begin
                                try
-                                       doc := Idispatch( OleVariant( BrowserRecord.Browser.ControlInterface ).Document ) as IHTMLDocument2;
-                                       doc.Body.ScrollTop := threadItem.ScrollTop;
+                                       doc := BrowserRecord.Browser.ControlInterface.Document as IHTMLDocument2;
+                                       (doc.body as IHTMLElement2).ScrollTop := threadItem.ScrollTop;
                                except
                                        on E: Exception do
                                                MsgBox(Handle, E.Message, 'SetContent[ScrollTop<-]', 0);
@@ -4553,7 +4584,7 @@ var
        stRes, edRes : Int64;
        browserRec : TBrowserRecord;
        threadNumber : String;
-       doc : Variant;
+       doc : IHTMLDocument2;
 begin
        stRes := 0;
        edRes := 0;
@@ -4581,8 +4612,9 @@ begin
                        browserRec.Move(IntToStr(stRes));
                        Thread.JumpAddress := 0;
                        try
-                               doc := Idispatch( OleVariant( browserRec.Browser.ControlInterface ).Document ) as IHTMLDocument2;
-                               Thread.ScrollTop := doc.Body.ScrollTop;
+                doc := browserRec.Browser.ControlInterface.Document as IHTMLDocument2;
+                if Assigned(doc) then
+                               Thread.ScrollTop := (doc.body as IHTMLElement2).ScrollTop;
                        except
                        end;
                end;
@@ -4783,8 +4815,8 @@ end;
 
 procedure TGikoForm.WndProc(var Message: TMessage);
 var
-       senderBrowser   : TWebBrowser;
-       url                                             : OleVariant;
+       senderBrowser : TWebBrowser;
+       url : OleVariant;
 begin
        try
                case Message.Msg of
@@ -4944,7 +4976,7 @@ end;
 
 function TGikoForm.OnDocumentContextMenu(Sender: TObject): WordBool;
 var
-       Doc: IHtmlDocument2;
+       doc: IHtmlDocument2;
        Range: IHTMLTxtRange;
        s: string;
        Num: Integer;
@@ -4952,26 +4984,31 @@ var
 begin
        Result := False;
        FactiveContent.IDAnchorPopup('');
-       Doc := FactiveContent.Browser.Document as IHtmlDocument2;
-       if Assigned(Doc) then begin
-               Range := Doc.selection.createRange as IHTMLTxtRange;
-               s := CustomStringReplace(Range.text, '\81@', ' ');//\91S\8ap\8bó\94\92\82ð\94¼\8ap\8bó\94\92\82É
-               s := ZenToHan(Trim(s));
-               if GikoSys.IsNumeric(s) then begin
-                       Num := StrToInt64Def(s, -1);
-                       ThreadItem := GetActiveContent(true);
-                       if (ThreadItem <> nil) and (Num <= ThreadItem.Count)
-                and (Num > 0)then begin
-                CreateResPopupBrowser;
-                FResPopupBrowser.CreateNewBrowser.PopupType := gptThread;
-                               HTMLCreater.SetResPopupText(FResPopupBrowser.CreateNewBrowser, ThreadItem, Num, Num, False, False);
-                FResPopupBrowser.Popup;
-                               Result := False;
-                       end else
-                               Result := True;
-               end else begin
+
+       doc := FactiveContent.Browser.ControlInterface.Document as IHtmlDocument2;
+       if not Assigned(doc) then
+        Exit;
+
+       Range := doc.selection.createRange as IHTMLTxtRange;
+       if not Assigned(Range) then
+        Exit;
+
+       s := CustomStringReplace(Range.text, '\81@', ' ');//\91S\8ap\8bó\94\92\82ð\94¼\8ap\8bó\94\92\82É
+       s := ZenToHan(Trim(s));
+       if GikoSys.IsNumeric(s) then begin
+               Num := StrToInt64Def(s, -1);
+               ThreadItem := GetActiveContent(true);
+               if (ThreadItem <> nil) and (Num <= ThreadItem.Count)
+           and (Num > 0)then begin
+           CreateResPopupBrowser;
+           FResPopupBrowser.CreateNewBrowser.PopupType := gptThread;
+                       HTMLCreater.SetResPopupText(FResPopupBrowser.CreateNewBrowser, ThreadItem, Num, Num, False, False);
+            FResPopupBrowser.Popup;
+               Result := False;
+               end else
                        Result := True;
-               end;
+    end else begin
+               Result := True;
        end;
 end;
 
@@ -6478,10 +6515,15 @@ end;
 
 /// \8dÅ\8f¬\89»\82³\82ê\82é
 procedure TGikoForm.OnMinimize;
+var
+    doc: IHTMLDocument2;
 begin
        if FActiveContent <> nil then begin
                FIsMinimize := mtMinimizing;
-               FActiveContent.Thread.ScrollTop := OleVariant(IHTMLDocument2(FActiveContent.Browser.Document)).Body.ScrollTop;
+        doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+        if Assigned(doc) then begin
+               FActiveContent.Thread.ScrollTop := (doc.body as IHTMLElement2).ScrollTop;
+        end;
        end;
 end;
 
@@ -6677,9 +6719,8 @@ end;
 
 procedure TGikoForm.OnResized;
 var
-       doc                                             : Variant;
+       doc : IHTMLDocument2;
 begin
-
        FOldFormWidth := Width;
        FIsIgnoreResize := rtNone;
 
@@ -6694,8 +6735,8 @@ begin
                begin
                        // \8dÅ\8f¬\89»\82Í\8aù\82É\8a®\97¹\82µ\82Ä\82¢\82é (\82Â\82Ü\82è\83^\83X\83N\83o\81[\82©\82ç\83E\83B\83\93\83h\83E\82ð\95\9c\8c³\92\86)
                        if FActiveContent <> nil then begin
-                               doc := Idispatch( olevariant(FActiveContent.Browser.ControlInterface).Document) as IHTMLDocument2;
-                               doc.Body.ScrollTop := FActiveContent.Thread.ScrollTop;
+                               doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+                               (doc.body as IHTMLElement2).ScrollTop := FActiveContent.Thread.ScrollTop;
                        end;
                        FIsMinimize := mtNone;
                end;
@@ -6709,69 +6750,81 @@ function TGikoForm.WebBrowserClick(Sender: TObject): WordBool;
 const
     LIMIT = 20;
 var
-       p : TPoint;
        e: IHTMLElement;
+    doc : IHTMLDocument2;
+    FOleInPlaceActiveObject: IOleInPlaceActiveObject;
+       p : TPoint;
        AID: string;
        stlist : TStringList;
        i, count: Integer;
        body : String;
     limited : Integer;
-    FOleInPlaceActiveObject: IOleInPlaceActiveObject;
 begin
-  result := true;
-  try
-       if (FActiveContent <> nil) and (FActiveContent.Browser <> nil) then
-        FOleInPlaceActiveObject := FActiveContent.Browser.ControlInterface as IOleInPlaceActiveObject;
-        FOleInPlaceActiveObject.OnFrameWindowActivate(True);
-               try
-                       GetCursorPos(p);
-                       p.x := p.x - FActiveContent.Browser.ClientOrigin.x;
-                       p.y := p.y - FActiveContent.Browser.ClientOrigin.y;
-                       e := IHTMLDocument2(FActiveContent.Browser.Document).elementFromPoint(p.x, p.y);
-                       if (Assigned(e)) then begin
-                               if (e.className = 'date') or (e.id = 'date') then begin
-                                       AID := e.innerText;
-                                       if AnsiPos('id', AnsiLowerCase(AID)) > 0 then begin
-                                               AID := Copy(AID, AnsiPos('id', AnsiLowerCase(AID)) - 1, 11);
-                       if AnsiPos(' be:', AnsiLowerCase(AID)) > 0 then begin
-                               AID := Copy(AID, 1, AnsiPos(' BE:', AnsiLowerCase(AID)) - 1)
-                        end;
-                                       end else begin
-                                               stlist := TStringList.Create;
-                                               try
-                                                       stList.DelimitedText := AID;
-                                                       AID := '';
-                                                       for i := 0 to stList.Count - 1 do
-                                                               if Length(WideString(stList[i])) = 8 then begin
-                                                                       if GikoSys.NotDateorTimeString(stList[i]) then begin
-                                                                               AID := stList[i];
-                                                                               break;
-                                                                       end;
-                                                               end;
-                                               finally
-                                                       stList.Free;
+       result := true;
+    if not Assigned(FActiveContent) then
+        Exit;
+    if not Assigned(FActiveContent.Browser) then
+        Exit;
+
+       try
+               FOleInPlaceActiveObject := FActiveContent.Browser.ControlInterface as IOleInPlaceActiveObject;
+               FOleInPlaceActiveObject.OnFrameWindowActivate(True);
+               GetCursorPos(p);
+               
+               p.x := p.x - FActiveContent.Browser.ClientOrigin.x;
+               p.y := p.y - FActiveContent.Browser.ClientOrigin.y;
+               
+               doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+               if not Assigned(doc) then
+                       Exit;
+
+               e := doc.elementFromPoint(p.x, p.y);
+               if not Assigned(e) then 
+                       Exit;
+               
+               if (e.className = 'date') or (e.id = 'date') then begin
+                       AID := e.innerText;
+                       if AnsiPos('id', AnsiLowerCase(AID)) > 0 then begin
+                               AID := Copy(AID, AnsiPos('id', AnsiLowerCase(AID)) - 1, 11);
+                               if AnsiPos(' be:', AnsiLowerCase(AID)) > 0 then begin
+                                       AID := Copy(AID, 1, AnsiPos(' BE:', AnsiLowerCase(AID)) - 1)
+                               end;
+                       end else begin
+                               stlist := TStringList.Create;
+                               try
+                                       stList.DelimitedText := AID;
+                                       AID := '';
+                                       for i := 0 to stList.Count - 1 do begin
+                                               if Length(WideString(stList[i])) = 8 then begin
+                                                       if GikoSys.NotDateorTimeString(stList[i]) then begin
+                                                               AID := stList[i];
+                                                               break;
+                                                       end;
                                                end;
                                        end;
-                    count := GikoSys.GetSameIDResCount(AID, FActiveContent.Thread);
-                    limited := LIMIT;
-                    if not (GikoSys.Setting.LimitResCountMessage) then begin
-                        limited := -1;
-                    end else if (count > LIMIT) then begin
-                        if (GikoUtil.MsgBox(Handle,
-                                IntToStr(LIMIT) + '\8cÂ\88È\8fã\82 \82è\82Ü\82·\82ª\81A\82·\82×\82Ä\95\\8e¦\82µ\82Ü\82·\82©\81H',
-                                'ID\83|\83b\83v\83A\83b\83v\8cx\8d\90',
-                                                               MB_YESNO or MB_ICONQUESTION) = ID_YES) then begin
-                            limited := -1;
-                        end
-                    end;
-                                       body := GikoSys.GetSameIDResAnchor(AID, FActiveContent.Thread, limited);
-                                       FActiveContent.IDAnchorPopup(body);
+                               finally
+                                       stList.Free;
                                end;
                        end;
-               except
+                       
+                       count := GikoSys.GetSameIDResCount(AID, FActiveContent.Thread);
+                       limited := LIMIT;
+                       if not (GikoSys.Setting.LimitResCountMessage) then begin
+                               limited := -1;
+                       end else if (count > LIMIT) then begin
+                               if (GikoUtil.MsgBox(Handle,
+                                               IntToStr(LIMIT) + '\8cÂ\88È\8fã\82 \82è\82Ü\82·\82ª\81A\82·\82×\82Ä\95\\8e¦\82µ\82Ü\82·\82©\81H',
+                                               'ID\83|\83b\83v\83A\83b\83v\8cx\8d\90',
+                                               MB_YESNO or MB_ICONQUESTION) = ID_YES) then begin
+                                       limited := -1;
+                               end
+                       end;
+
+                       body := GikoSys.GetSameIDResAnchor(AID, FActiveContent.Thread, limited);
+                       FActiveContent.IDAnchorPopup(body);
                end;
-  except
-  end;
+       except
+       end;
 end;
 
 //\83X\83\8c\83b\83h\88ê\97\97\82ð\8dÅ\91å\89»\82µ\82Ä\83t\83H\81[\83J\83X\82ð\93\96\82Ä\82é
@@ -7160,15 +7213,22 @@ end;
 //\82±\82Ì\83\8c\83X\82 \82Ú\81`\82ñ
 procedure TGikoForm.IndividualAbon(Atag, Atype : Integer);
 var
-       ThreadItem      : TThreadItem;
-       ReadList                : TStringList;
-       wordCount               : TWordCount;
+    doc : IHTMLDocument2;
+       ThreadItem : TThreadItem;
+       ReadList : TStringList;
+       wordCount : TWordCount;
 begin
-       ThreadItem      := GetActiveContent(True);
-       ReadList                := TStringList.Create;
-       wordCount               := TWordCount.Create;
+    if not Assigned(FActiveContent) then
+        Exit;
+    doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+    if not Assigned(doc) then
+        Exit;
+
+       ThreadItem := GetActiveContent(True);
+       ReadList := TStringList.Create;
+       wordCount := TWordCount.Create;
        try
-               ThreadItem.ScrollTop := OleVariant(IHTMLDocument2(FActiveContent.Browser.Document)).Body.ScrollTop;
+               ThreadItem.ScrollTop := (doc.body as IHTMLElement2).ScrollTop;
 {$IFDEF SPAM_FILTER_ENABLED}
                // \83X\83p\83\80\82É\90Ý\92è
                ReadList.LoadFromFile( ThreadItem.GetThreadFileName );
@@ -7189,6 +7249,7 @@ end;
 //\93¯\88êID\82ðNG\83\8f\81[\83h\82É\93o\98^
 procedure TGikoForm.AddIDtoNGWord(invisible : boolean);
 var
+    doc : IHTMLDocument2;
        ThreadItem : TThreadItem;
        No : Integer;
 {$IFDEF SPAM_FILTER_ENABLED}
@@ -7238,7 +7299,11 @@ begin
     end;
 {$ENDIF}
     if (FActiveContent.Repaint) then begin
-        ThreadItem.ScrollTop := OleVariant(IHTMLDocument2(FActiveContent.Browser.Document)).Body.ScrollTop;
+        doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+
+        if not Assigned(doc) then
+            Exit;
+        ThreadItem.ScrollTop := (doc.body as IHTMLElement2).ScrollTop;
         if ThreadItem <> nil then
             InsertBrowserTab( ThreadItem, True );
     end;
@@ -7264,7 +7329,7 @@ begin
                ReadList                := TStringList.Create;
                wordCount               := TWordCount.Create;
                try
-                       ThreadItem.ScrollTop := OleVariant(IHTMLDocument2(FActiveContent.Browser.Document)).Body.ScrollTop;
+                       ThreadItem.ScrollTop := FActiveContent.Browser.OleObject.Document.Body.ScrollTop;
 {$IFDEF SPAM_FILTER_ENABLED}
                        // \83X\83p\83\80\82É\90Ý\92è
                        ReadList.LoadFromFile( ThreadItem.GetThreadFileName );
@@ -7294,14 +7359,17 @@ end;
 procedure TGikoForm.KokoPopupMenuPopup(Sender: TObject);
 var
        firstElement: IHTMLElement;
-       document: IHTMLDocument2;
+       doc: IHTMLDocument2;
 begin
-       document := FActiveContent.Browser.Document as IHTMLDocument2;
-       if Assigned(document) then
-               firstElement := document.all.item('idSearch', 0) as IHTMLElement;
-               if Assigned(firstElement) then
-                       if firstElement.style.visibility <> 'hidden' then
-                               firstElement.style.visibility := 'hidden';
+    try
+       doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+           if Assigned(doc) then
+                   firstElement := doc.all.item('idSearch', 0) as IHTMLElement;
+               if Assigned(firstElement) then
+                       if firstElement.style.visibility <> 'hidden' then
+                               firstElement.style.visibility := 'hidden';
+    except
+    end;
 end;
 
 procedure TGikoForm.RepaintAllTabsBrowser();
@@ -7484,6 +7552,7 @@ begin
        BrowserNullTab.Browser.Navigate(BLANK_HTML);
 
        FBrowsers := TList.Create;
+
        for i := 0 to count -1 do begin
                FBrowsers.Add(TWebBrowser.Create(BrowserPanel));
                newBrowser := FBrowsers[FBrowsers.Count - 1];
@@ -7499,6 +7568,8 @@ begin
                newBrowser.OnStatusTextChange   := BrowserStatusTextChange;
                newBrowser.Navigate(BLANK_HTML);
                ShowWindow(newBrowser.Handle, SW_HIDE);
+        GikoSys.ShowRefCount('Browser' + IntToStr(i), newBrowser.ControlInterface);
+        GikoSys.ShowRefCount('Document' + IntToStr(i), newBrowser.ControlInterface.Document);
        end;
        BrowserNullTab.Browser.BringToFront;
        ShowWindow(BrowserNullTab.Browser.Handle, SW_SHOW);
index 032e13e..bbfebf1 100644 (file)
@@ -2338,14 +2338,16 @@ procedure TGikoDM.KokomadeActionExecute(Sender: TObject);
 var
        No: Integer;
        ThreadItem: TThreadItem;
+    doc : IHTMLDocument2;
 begin
        No := GikoForm.KokoPopupMenu.Tag;
-       if No = 0 then Exit;
+       if No = 0
+        then Exit;
        ThreadItem := GikoForm.GetActiveContent(True);
-       if ThreadItem = nil then Exit;
+       if not Assigned(ThreadItem) then
+        Exit;
        ThreadItem.Kokomade := No;
-       GikoForm.ActiveContent.Thread.ScrollTop :=
-               OleVariant(IHTMLDocument2(GikoForm.ActiveContent.Browser.Document)).Body.ScrollTop;
+       GikoForm.ActiveContent.Thread.ScrollTop := GikoForm.ActiveContent.Browser.OleObject.Document.Body.ScrollTop;
        GikoForm.ActiveContent.Repaint := true;
        GikoForm.InsertBrowserTab(GikoForm.ActiveContent.Thread, true);
        //INFO 2005/11/19 \88ê\92U\89B\95Á\81A\95K\97v\82È\82çGikoForm\82Ì\95û\82É\83\81\83\\83b\83h\82ð\92Ç\89Á\82·\82é
@@ -2361,8 +2363,7 @@ begin
        ThreadItem := GikoForm.GetActiveContent(True);
        if ThreadItem = nil then Exit;
        ThreadItem.Kokomade := -1;
-       GikoForm.ActiveContent.Thread.ScrollTop :=
-               OleVariant(IHTMLDocument2(GikoForm.ActiveContent.Browser.Document)).Body.ScrollTop;
+       GikoForm.ActiveContent.Thread.ScrollTop := GikoForm.ActiveContent.Browser.OleObject.Document.Body.ScrollTop;
        GikoForm.ActiveContent.Repaint := true;
        GikoForm.InsertBrowserTab(GikoForm.ActiveContent.Thread, true);
        //INFO 2005/11/19 \88ê\92U\89B\95Á\81A\95K\97v\82È\82çGikoForm\82Ì\95û\82É\83\81\83\\83b\83h\82ð\92Ç\89Á\82·\82é
@@ -2454,8 +2455,7 @@ begin
        IndividualForm := TIndividualAbonForm.Create(GikoForm);
        try
                ThreadItem := GikoForm.GetActiveContent(True);
-               ThreadItem.ScrollTop :=
-                       OleVariant(IHTMLDocument2(GikoForm.ActiveContent.Browser.Document)).Body.ScrollTop;
+               ThreadItem.ScrollTop := GikoForm.ActiveContent.Browser.OleObject.Document.Body.ScrollTop;
                if (ThreadItem <> nil) and (ThreadItem.IsLogFile) then begin
                        if IndividualForm.SetThreadLogFileName(ThreadItem.GetThreadFileName) then begin
                                ReadList                := TStringList.Create;
@@ -2502,8 +2502,7 @@ begin
        IndividualForm := TIndividualAbonForm.Create(GikoForm);
        try
                ThreadItem := GikoForm.GetActiveContent(True);
-               ThreadItem.ScrollTop :=
-                       OleVariant(IHTMLDocument2(GikoForm.ActiveContent.Browser.Document)).Body.ScrollTop;
+               ThreadItem.ScrollTop := GikoForm.ActiveContent.Browser.OleObject.Document.Body.ScrollTop;
                if (ThreadItem <> nil) and (ThreadItem.IsLogFile) then begin
                        if IndividualForm.SetThreadLogFileName(ThreadItem.GetThreadFileName) then begin
                                if (IndividualForm.ShowModal = mrOK) then begin
@@ -4113,7 +4112,7 @@ end;
 procedure TGikoDM.BackToHistory(item: TMoveHistoryItem);
 var
     browser : TWebBrowser;
-    doc : OleVariant;
+    doc : IHTMLDocument2;
 begin
     if ( item <> nil ) then begin
         if ( GikoForm.GetActiveContent = item.ThreadItem ) then begin
@@ -4121,8 +4120,8 @@ begin
                 .Objects[GikoForm.BrowserTab.TabIndex]).Browser;
             if (browser <> nil) then begin
                 try
-                    doc := Idispatch( olevariant(browser.ControlInterface).Document) as IHTMLDocument2;
-                    doc.Body.ScrollTop := item.ScrollTop;
+                    doc := browser.ControlInterface.Document as IHTMLDocument2;
+                    (doc.body as IHTMLElement2).ScrollTop := item.ScrollTop;
                 except
                 end;
             end;
@@ -4172,6 +4171,7 @@ procedure TGikoDM.ClickActiveElementActionExecute(Sender: TObject);
 var
     browser : TWebBrowser;
     elem : IHTMLElement;
+    doc : IHTMLDocument2;
 begin
     if (GikoForm.GetActiveContent <> nil) then begin
         if (GikoForm.BrowserTab.Tabs.Count > 0) and
@@ -4180,8 +4180,13 @@ begin
                 .Objects[GikoForm.BrowserTab.TabIndex]).Browser;
             if (browser <> nil) then begin
                 try
-                    elem := IHTMLDocument2(browser.Document).activeElement;
-                    elem.click;
+                    doc := browser.ControlInterface.Document as IHTMLDocument2;
+                    if Assigned(doc) then begin
+                        elem := doc.activeElement;
+                        if Assigned(elem) then begin
+                            elem.click;
+                        end;
+                    end;
                 except
                 end;
             end;
@@ -4342,6 +4347,7 @@ end;
 function TGikoDM.GetActiveThreadLinks : IHTMLElementCollection;
 var
     browser : TWebBrowser;
+    doc : IHTMLDocument2;
 begin
     Result := nil;
     if (GikoForm.GetActiveContent <> nil) then begin
@@ -4351,7 +4357,10 @@ begin
                 .Objects[GikoForm.BrowserTab.TabIndex]).Browser;
             if (browser <> nil) then begin
                 try
-                    Result := IHTMLDocument2(browser.Document).links;
+                    doc := browser.ControlInterface.Document as IHTMLDocument2;
+                    if Assigned(doc) then begin
+                        Result := doc.links;
+                    end;
                 except
                     Result := nil;
                 end;
index 7642a5b..e56dec2 100644 (file)
@@ -257,6 +257,8 @@ type
         //! \83t\83@\83C\83\8b\96¼\82©\82ç\82Ì\83X\83\8c\83b\83h\8dì\90¬\93ú\82Ì\8eæ\93¾
         function GetCreateDateFromName(FileName: String): TDateTime;
         function GetExtpreviewFileName: String;
+
+        procedure ShowRefCount(msg: String; unk: IUnknown);
        end;
 
 var
@@ -3475,6 +3477,25 @@ begin
     Result := UnixToDateTime(unixtime) + OffsetFromUTC;
 end;
 
+procedure TGikoSys.ShowRefCount(msg: String; unk: IUnknown);
+var
+    count : integer;
+begin
+    if not Assigned(unk) then
+        Exit;
+
+{$IFDEF DEBUG}
+    try
+        unk._AddRef;
+        count := unk._Release;
+
+               Writeln(msg + ' RefCount=' + IntToStr(count));
+    except
+               Writeln(msg + ' RefCount=exception!!');
+       end;
+{$ENDIF}
+end;
+
 initialization
        GikoSys := TGikoSys.Create;
 
index b010219..21d5d3d 100644 (file)
@@ -32,7 +32,7 @@ type
                //! \89½\8ds\82Ü\82Å\82½\82ß\82é\82©\82Ì\83T\83C\83Y
                FBuffSize: Integer;
                //! \83u\83\89\83E\83U\82ÌIHTMLDocument2\83C\83\93\83^\83t\83F\81[\83X\82ð\95Û\8e\9d\82·\82é open\82©\82çclose\82Ì\8aÔ\82Å
-               FBrowserDoc: Variant;
+               FBrowserDoc: OleVariant;
        public
                constructor Create(Browser: TWebBrowser; BuffSize: Integer);
                destructor Destory;
@@ -1612,7 +1612,7 @@ begin
 end;
 procedure TBufferedWebBrowser.Open;
 begin
-       FBrowserDoc := Idispatch( olevariant(FBrowser.ControlInterface).Document);
+       FBrowserDoc := FBrowser.ControlInterface.Document;
        FBrowserDoc.open;
        FBrowserDoc.charset := 'Shift_JIS';
 end;
index a913b37..0a984a6 100644 (file)
@@ -105,18 +105,26 @@ end;
 function TMoveHistory.pushItem( item: TBrowserRecord): Integer;
 var
     history : TMoveHistoryItem;
-    doc : OleVariant;
+    doc : IHTMLDocument2;
 begin
     Result := -1;
-    if ( item <> nil ) and ( item.Thread <> nil )
-        and ( item.Browser <> nil) then begin
-        history := TMoveHistoryItem.Create;
-        history.FThreadItem := item.Thread;
-        doc := Idispatch( olevariant(item.Browser.ControlInterface).Document) as IHTMLDocument2;
-        history.ScrollTop := doc.Body.ScrollTop;
+    if not Assigned(item) then
+        Exit;
+    if not Assigned(item.Thread) then
+        Exit;
+    if not Assigned(item.Browser) then
+        Exit;
 
-        Result := pushItem( history );
-    end;
+    doc := item.Browser.ControlInterface.Document as IHTMLDocument2;
+    if not Assigned(doc) then
+        Exit;
+
+    history := TMoveHistoryItem.Create;
+    history.FThreadItem := item.Thread;
+
+    history.ScrollTop := (doc.body as IHTMLElement2).ScrollTop;
+
+    Result := pushItem( history );
 end;
 //! \88ê\82Â\91O\82Ì\97\9a\97ð\83A\83C\83e\83\80\8eæ\93¾
 function TMoveHistory.getPrevItem(item: TBrowserRecord): TMoveHistoryItem;
index 6d32fcc..d9102d6 100644 (file)
@@ -1492,12 +1492,12 @@ end;
 
 procedure TOptionDialog.CSSSetContent(Content: string);
 var
-       doc : Variant;
+       doc : OleVariant;
 begin
        if CSSBrowser.Document <> nil then begin
-               doc := CSSBrowser.Document;
+               doc := CSSBrowser.OleObject.Document;
                doc.open;
-                               doc.Clear;
+        doc.Clear;
                doc.charset := 'Shift_JIS';
                doc.Write(Content);
                doc.Close;
index 6039ba3..8238d2e 100644 (file)
@@ -165,9 +165,8 @@ end;
 procedure TResPopupBrowser.Write(ADocument: String; OnlyTitle: Boolean = False);
 var
        p: TPoint;
-    doc: Variant;
+    doc: OleVariant;
        ARect: TRect;
-    FDispHtmlDocument: DispHTMLDocument;
 begin
     try
         // \83^\83X\83N\83o\81[\82©\82ç\8fÁ\82·
@@ -177,7 +176,7 @@ begin
         SetWindowPos(Self.Handle, HWND_BOTTOM,
             p.X, p.Y, 50 , 50,
             SWP_NOACTIVATE or SWP_HIDEWINDOW);
-        doc := Idispatch( olevariant(Self.ControlInterface).Document) as IHTMLDocument2;
+        doc := Self.OleObject.Document;
         doc.open;
         doc.charset := 'Shift_JIS';
         doc.Write('<html><head>'#13#10 +
@@ -193,8 +192,7 @@ begin
         ARect := CalcRect(Screen.MonitorFromPoint(p).WorkareaRect,
                         not OnlyTitle);
 
-        FDispHtmlDocument := Idispatch(OleVariant(Self.ControlInterface).Document) as DispHTMLDocument;
-        FEvent := THTMLDocumentEventSink.Create(Self, FDispHtmlDocument, HTMLDocumentEvents2);
+        FEvent := THTMLDocumentEventSink.Create(Self, Self.Document, HTMLDocumentEvents2);
         FEvent.OnClick := ResPopupBrowserClick;
         FEvent.OnDoubleClick := ResPopupBrowserDbClick;
         Self.Visible := True;
@@ -415,8 +413,7 @@ begin
 
     try
         top := 0;
-        item := OleVariant( Self.Document as IHTMLDocument2)
-                .anchors.item(OleVariant('bottom'));
+        item := Self.OleObject.Document.anchors.item(OleVariant('bottom'));
         item.focus();
         repeat
             top := top + item.offsetTop;
index c3bc602..2af53c6 100644 (file)
@@ -1,3 +1,15 @@
+\81`TWebBrowser\82Ì\9d|\81`
+       Delphi\82Ì\83I\81[\83g\83\81\81[\83V\83\87\83\93\82Í\82í\82©\82è\93ï\82­\81A\8bC\82ð\94²\82­\82Æ\8eQ\8fÆ\83J\83E\83\93\83g\82ª\8c¸\82è\82·\82¬\82Ä\82µ\82Ü\82Á\82½\82è\81A\8ec\82Á\82Ä\82µ\82Ü\82¢\82Ü\82·\81B
+       eggcake\82ª\92²\82×\82½\82±\82ê\82ç\82ð\89ñ\94ð\82·\82é\95û\96@\82ð\82±\82±\82É\8f\91\82¢\82Ä\82¨\82«\82Ü\82·\81B
+       
+       \90³\82µ\82¢\95û\96@
+               if Assigned(WebBrowser.ControlInterface.Document) then;
+               OleVariant := OleVariant(WebBrowser.Document);
+               OleVariant := WebBrowser.OleObject.Document;
+               IHTMLDocument2 := WebBrowser.ControlInterface.Document as IHTMLDocument2;
+               IHTMLDocument2 := IDispatch(OleVariant(WebBrowser.Document)) as IHTMLDocument2;
+               IHTMLDocument2 := IDispatch(WebBrowser.OleObject.Document) as IHTMLDocument2;
+
 \81E\83\8c\83X\91\97\90M\83G\83f\83B\83^\82Ì\81u\91\97\90M\94 \82Ö\95Û\91\81v\82ª\96¢\8eÀ\91\95\81B
 \81@\82æ\82Á\82Ó\82¡\81`\93I\82É\82Í\96³\82­\82Ä\82à\82¢\82¢\82Æ\8ev\82¤\81B