I've got a nagging problem that I've beat my head against for years...maybe the collective brain of ProFox will provide the a clue to a solution.

I have a form that contains an instance of the IE OLE Control (_webbrowser4 from the _webview.vcx library). Nothing odd, just a simple form and a "Shell.Explorer.2" OleClass on it, named "web".

I load a large HTML file into the "web" object. Works great.
I need to search the contents of the HTML file. That's where the problem is.

I use the following code (below)...and it randomly throws the error
            Error 1943
            Member BODY does not evaluate to an object

The offending line is always:  oRange = .document.BODY.createTextRange()

What the code does is
1. make sure the user hasn't started searching for a string before the entire file is loaded
    2. check for a bookmark (related to the IE search functionality)
a. if a book mark exists, only retrieve the portion of the HTML that starts at the book mark through the end b. if no book mark exists, our search range will be the entire document
    3. create a text range to search based on step #2
4. use FindText search and if found move the display to show the found string
    5. move the IE internal pointer to our found search string
    6. store the remaining HTML content for future search
    7. if nothing found, notify user

I -THINK- my problem may be because the user is searching before the HTML file is finished loading, therefore the IE object won't be able or willing to return a reference to the entire body object content.

So, if my suspicions are correct, what IE value should I check, other than "busy" and "readystate" which I'm already checking?

Any suggestions appreciated! Any suggestions leading to a solution gets a gold star!

Mike Copeland

** CODE START
strFind = ALLTRIM(thisform.searchstring.txt.Value) && a textbox on the form to type search string into
lnSeconds = SECONDS()

DO WHILE (Thisform.web.OBJECT.Busy OR Thisform.web.OBJECT.ReadyState <> 4) AND (SECONDS() - lnSeconds) < 30
        DOEVENTS
ENDDO

sBookMark=thisform.bookmark
oRange=[]
DECLARE Sleep IN Win32API INTEGER nMilliseconds
IF !EMPTY(strFind)
    WITH thisform.web
        IF !vartype(sBookMark)='O' OR ISNULL(sBookMark)
oRange = .document.body.createTextRange() && RANDOM ERROR TRIGGERED HERE!!!
        ELSE
            oRange = sBookMark
        ENDIF
        IF !vartype(sBookMark)='O' OR ISNULL(sBookMark)
            oRange = .document.body.createTextRange()
        ENDIF
        IF oRange.findText(strFind,1000000000)
            oRange.select()
            oRange.movestart('word')
            thisform.bookmark = oRange
        ELSE
            IF oRange.findtext=.f.
                MESSAGEBOX('Sorry, unable to find more occurances of'+;
                    CHR(13)+CHR(13)+CHR(9)+strFind,0+16,'Not Found',3000)
                thisform.bookmark=.null.
            ENDIF
        ENDIF
    ENDWITH
ENDIF

** CODE END

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to