OSDN Git Service

スレ一覧の絞込みでCTRL+DELで個別に削除できるように修正
[gikonavigoeson/gikonavi.git] / BrowserRecord.pas
index 8a1da49..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,28 +93,30 @@ 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;
 // *************************************************************************
@@ -115,24 +124,23 @@ end;
 // *************************************************************************
 procedure TBrowserRecord.Move(scroll: Integer);
 var
-       top: Integer;
-       item: OleVariant;
+    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;
 
@@ -143,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;
 {
@@ -186,37 +195,15 @@ const
 var
        CmdTarget : IOleCommandTarget;
        vaIn, vaOut: OleVariant;
-       PtrGUID: PGUID;
 begin
-       if (Self.Browser <> nil) and (Self.Browser.Document <> 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;
+       if Assigned(Self.Browser) then begin
+               try
+                       CmdTarget := Self.Browser.ControlInterface.Document as IOleCommandTarget;
+                       if Assigned(CmdTarget) then begin
+                               CmdTarget.Exec(@CGID_WebBrowser, HTMLID_FIND, 0, vaIn, vaOut);
+                       end;
+               except
                end;
-        vaIn  := 0;
-        vaOut := 0;
-               New(PtrGUID);
-               PtrGUID^ := CGID_WebBrowser;
-        try
-               try
-                       if Self.Browser.Document
-                    .QueryInterface(IOleCommandTarget, CmdTarget)
-                    = S_OK then begin
-                           if CmdTarget <> nil then begin
-                                   try
-                                           CmdTarget.Exec(PtrGUID, HTMLID_FIND, 0, vaIn, vaOut);
-                                       finally
-                                               CmdTarget._Release;
-                                       end;
-                               end;
-                end;
-                   except
-                   end;
-        finally
-               Dispose(PtrGUID);
-        end;
        end;
 end;