Page 33 of 39
Posted: Thu Mar 12, 2009 4:25 pm
by srod
Kwai, it works fine here if I remove the 'https' business.
The following mixes your code with some previous COMate code and runs fine here with both the webgadget and an IE instance.
I think this confirms that it is indeed an 'access denied' problem that you are experiencing for some reason.
Code: Select all
;/////////////////////////////////////////////////////////////////////////////////
;***COMate*** COM automation through iDispatch.
;*===========
;*
;*Execute JavaScript in WebGadget demo by Timo Harter (Freak), Ricardo and Stephen Rodriguez.
;/////////////////////////////////////////////////////////////////////////////////
IncludePath "..\"
XIncludeFile "COMate.pbi"
Enumeration
#FormWeb
#WebGadget
#IEExplorer
EndEnumeration
Define.COMateObject WebObject
Global WebObjectWait.COMateObject
Global HTTPObject.COMateObject
Procedure.i ExecuteJavaScript(Command$)
Protected DocumentDispatch.COMateObject, Script.COMateObject
Protected Result
If HTTPObject
DocumentDispatch = HTTPObject\GetObjectProperty("Document")
If DocumentDispatch
Script = DocumentDispatch\GetObjectProperty("script")
If Script
Result = Script\Invoke("eval('" + command$ + "')")
Script\release()
EndIf
DocumentDispatch\Release()
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Procedure LoopWait()
WebObjectWait = COMate_WrapCOMObject(GetWindowLong_(GadgetID(#WebGadget), #GWL_USERDATA))
Status = - 1
If WebObjectWait
While Status
While WindowEvent():Delay(1):Wend
Status = WebObjectWait\GetIntegerProperty("Busy")
Wend
WebObjectWait\Release()
EndIf
EndProcedure
Procedure OuvreClientWeb(Url.s, Client = #IEExplorer)
If Client = #WebGadget
If IsGadget(Client)
HTTPObject = COMate_WrapCOMObject(GetWindowLong_(GadgetID(Client), #GWL_USERDATA))
SetGadgetText(Client, Url)
LoopWait()
EndIf
ElseIf #IEExplorer
HTTPObject = COMate_CreateObject("InternetExplorer.Application")
If HTTPObject
HTTPObject\SetProperty("Visible= #True")
HTTPObject\invoke("Navigate('" + Url + "')")
While Status$ <> "Done"
Status$ = HTTPObject\GetStringProperty("StatusText")
Delay(10)
Wend
Delay(1000)
EndIf
EndIf
EndProcedure
OpenWindow(#FormWeb, 0, 0, 800, 600, "", #PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
WebGadget(#WebGadget, 10, 10, WindowWidth(#FormWeb) - 20, WindowHeight(#FormWeb) - 60, "")
; First method with webgadget
;OuvreClientWeb("http://www.purebasic.fr/english/posting.php?mode=reply&t=33983", #WebGadget)
;xMessage$ = "Hello from PB :)"
;ExecuteJavaScript("document.all.message.value=" + Chr(34) + xMessage$ + Chr(34))
;ExecuteJavaScript("document.all.preview.click()")
; Second method with IE client
OuvreClientWeb("http://www.purebasic.fr/english/posting.php?mode=reply&t=33983", #IEExplorer)
xMessage$ = "Hello from PB :)"
ExecuteJavaScript("document.all.message.value=" + Chr(34) + xMessage$ + Chr(34))
ExecuteJavaScript("document.all.preview.click()")
Repeat
Evenement = WaitWindowEvent()
Until Evenement = #PB_Event_CloseWindow
HTTPObject\Release()
End
Posted: Thu Mar 12, 2009 4:29 pm
by ricardo
I just download tailbite and tried to create COMate as lib but get an error:
undefined symbol 'COMate_COMate_Class_Invoke"
What can i do?
Thanks
Posted: Thu Mar 12, 2009 4:30 pm
by Kwai chang caine
but if you want to send the webgadget to navigate, dont need to wrapp the webgadget
Hello RICARDO glad to call you
But if i don't Wrap the WebGadget....how can i use it after with the "ExecuteJavaScript(Command$)" procedure ???? :roll:
Posted: Thu Mar 12, 2009 4:33 pm
by srod
ricardo wrote:I just download tailbite and tried to create COMate as lib but get an error:
undefined symbol 'COMate_COMate_Class_Invoke"
What can i do?
Thanks
Don't use Tailbite!
Why would you want to Tailbite this library; surely in source code form it is just as convenient, if not more so?
Must admit that I have not kept up with any Tailbite / user-lib issues because I will no longer use closed libs other than dll's so I can't really comment on what might be wrong here.
Posted: Thu Mar 12, 2009 4:35 pm
by ricardo
Kwaï chang caïne wrote:but if you want to send the webgadget to navigate, dont need to wrapp the webgadget
Hello RICARDO glad to call you
But if i don't Wrap the WebGadget....how can i use it after with the "ExecuteJavaScript(Command$)" procedure ???? :roll:
Just add srod's procedure
Code: Select all
Procedure.i ExecuteJavaScript(Gadget, command$)
Protected browser.COMateObject, documentDispatch.COMateObject, script.COMateObject
Protected result
browser = COMate_WrapCOMObject(GetWindowLong_(GadgetID(gadget), #GWL_USERDATA))
If browser
documentDispatch = browser\GetObjectProperty("Document")
If documentDispatch
script = documentDispatch\GetObjectProperty("script")
If script
result = script\Invoke("eval('" + command$ + "')")
script\release()
EndIf
documentDispatch\Release()
EndIf
browser\Release()
EndIf
ProcedureReturn result
EndProcedure
And us your webgadget as usuall
Posted: Thu Mar 12, 2009 4:38 pm
by ricardo
srod wrote:ricardo wrote:I just download tailbite and tried to create COMate as lib but get an error:
undefined symbol 'COMate_COMate_Class_Invoke"
What can i do?
Thanks
Don't use Tailbite!
Why would you want to Tailbite this library; surely in source code form it is just as convenient, if not more so?
Must admit that I have not kept up with any Tailbite / user-lib issues because I will no longer use closed libs other than dll's so I can't really comment on what might be wrong here.
I want to Tailbite it because, in first place i can then code and run unsaved stuff, just for testing.
And even if i save it, i always have to carry and reference the XIncludeFile "COMate.pbi", a lib is much more comfortable for me.
I understand your point about opensource libs, but creating the lib is just for more handly managment of people born in latin countries

Posted: Thu Mar 12, 2009 4:43 pm
by ricardo
Otherwise i need a new PB Command to overwrite
Code: Select all
IncludePath "..\"
XIncludeFile "COMate.pbi"
by
Code: Select all
IncludePath "I dont remember where it is!!!"
XIncludeFile "COMate.pbi"
Posted: Thu Mar 12, 2009 4:51 pm
by Kwai chang caine
I think this confirms that it is indeed an 'access denied' problem that you are experiencing for some reason.
Yes probably
But that when even strange this history that why the webgadget is different of IE client :roll:
Because, i believe, it's exactly the same motor no ??
In the same time i try to convert a VB code to PB.
But obviously i can't, it's a mass murder
I try to use directly the COM to pilot IE, for see if i can around my problem
This is my cowpat
Code: Select all
IncludeFile "COMate.pbi"
Define.COMateObject WebObject
Global HTTPObject.COMateObject
Global HTML_Txt_Search.COMateObject
Global HTML_Form_Search.COMateObject
HTTPObject = COMate_CreateObject("InternetExplorer.Application")
If HTTPObject
HTTPObject\SetProperty("Visible= #True")
HTTPObject\invoke("Navigate('http://www.Ebay.fr/')")
HTML_Txt_Search\invoke("Doc.All.Item('satitle')")
HTML_Form_Search\invoke("Doc.Forms('headerSearch')")
While status$ <> "Terminé"
Status$ = HTTPObject\GetStringProperty("StatusText")
Delay(10)
Wend
HTML_Txt_Search\SetProperty("Value=PureBasic")
HTML_Form_Search\SetProperty("submit")
HTTPObject\Release()
EndIf
And this is the VB code
Code: Select all
Option Explicit
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private WithEvents IE As InternetExplorer
Private HTML_Txt_Search As HTMLInputElement
Private WithEvents HTML_Form_Search As HTMLFormElement
Private Sub Form_Load()
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate "http://www.ebay.fr"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
IE.Quit
Set IE = Nothing
End Sub
Private Function HTML_Form_Search_onsubmit() As Boolean
If MsgBox("Voulez-vous lancer la recherche ?", vbYesNoCancel Or vbQuestion, "confirmation") <> vbYes Then
HTML_Form_Search_onsubmit = False
End If
End Function
Private Sub IE_DownloadComplete()
Dim Doc As IHTMLDocument2
Dim nCount As Integer
If IE.LocationURL = "http://www.ebay.fr/" Then
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
Set Doc = IE.document
On Error Resume Next
nCount = Doc.All.Item("satitle").length
On Error GoTo 0
If nCount > 1 Then
Set HTML_Txt_Search = Doc.All.Item("satitle").Item(0)
Else
Set HTML_Txt_Search = Doc.All.Item("satitle")
End If
Set HTML_Form_Search = Doc.Forms("headerSearch")
Btn_Search.Enabled = (Not HTML_Form_Search Is Nothing) And (Not HTML_Form_Search Is Nothing)
Txt_Search.Enabled = Btn_Search.Enabled
End If
End Sub
Private Sub Txt_Search_Change()
HTML_Txt_Search.Value = Txt_Search.Text
End Sub
Private Sub Btn_Search_Click()
HTML_Form_Search.submit
End Sub
Thanks SROD
Like the GODS.....can you show me the way

Posted: Thu Mar 12, 2009 5:15 pm
by Kwai chang caine
I don't know if that can help you, but i have simplify at the maximum the VB code.
My mind is good, by the COM, the private job site works fine with this code
Code: Select all
Private WithEvents IE As InternetExplorer
Private HTML_Txt_Login As HTMLInputElement
Private HTML_Txt_Pass As HTMLInputElement
Private WithEvents HTML_Form As HTMLFormElement
Private Sub Form_Load()
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate "https://SitePrivate/index.jsp"
End Sub
Private Sub IE_DownloadComplete()
'Dim Doc As IHTMLDocument2 <--- that's works with or without this line
Set Doc = IE.document
Set HTML_Txt_Login = Doc.All.Item("name")
Set HTML_Txt_Pass = Doc.All.Item("pass")
Set HTML_Form = Doc.Forms("theform")
End Sub
Private Sub Btn_Search_Click()
HTML_Txt_Login.Value = "xxxx"
HTML_Txt_Pass.Value = "xxxx"
HTML_Form.submit
End Sub
Posted: Thu Mar 12, 2009 6:59 pm
by srod
Kwai, for once we agree, that translation of yours certainly is a cowpat!
I could translate for you, but I can't be bothered right now - I'm simply too busy! Perhaps someone else will do it for you? To be honest, with all of your COMate experience now, you should be able to translate that quite quickly.
Posted: Thu Mar 12, 2009 10:34 pm
by SFSxOI
This seems to work:
Code: Select all
index= objCollection\GetIntegerProperty("Add(" + Str(objItemColl) + " as COMateobject)")
The 'as COMateobject' was the secret. I had done GetIntegerProperty once before but never even thought about the 'as COMateobject'.
Thanks srod

Posted: Thu Mar 12, 2009 11:17 pm
by srod
SFSxOI wrote:This seems to work:
Code: Select all
index= objCollection\GetIntegerProperty("Add(" + Str(objItemColl) + " as COMateobject)")
The 'as COMateobject' was the secret. I had done GetIntegerProperty once before but never even thought about the 'as COMateobject'.
Thanks srod

Only way of passing a COM object which has been wrapped up in a COMate object!

Posted: Fri Mar 13, 2009 11:26 am
by Kwai chang caine
Kwai, for once we agree, that translation of yours certainly is a cowpat!
To be honest, with all of your COMate experience now, you should be able to translate that quite quickly.
If you can say right......
I so much like, give to you the true mind
But a gravel for you is a rock for KCC
When you are come great like you....i understand it's so difficult for you to understand my difficulty.
How a runner champion, can be understand, the baby who just be born when he can't just walking
Perhaps someone else will do it for you?
Perhaps ......i begin to pray
Our father who is in the sky, that your name is sanctified...
I could translate for you, but I can't be bothered right now - I'm simply too busy!
Never mind....I don't know your are so busy

I never want disturb you, never never
Your works is more important...you are right

You give us so much already
I wish you a good day
Posted: Fri Mar 13, 2009 11:49 am
by srod
Okay, I have tested the following on a non-https site (the PB forums as it was!) and it works fine :
Code: Select all
IncludePath "..\"
XIncludeFile "COMate.pbi"
Global IE.COMateObject, HTML_Txt_Login.COMateObject, HTML_Txt_Pass.COMateObject, HTML_Form.COMateObject
;Returns #True if successful.
Procedure.i Form_Load()
Protected result = #False
IE = COMate_CreateObject("InternetExplorer.Application")
If IE
IE\SetProperty("Visible= #True")
IE\Invoke("Navigate('https://SitePrivate/index.jsp')")
While Status$ <> "Done"
Status$ = IE\GetStringProperty("StatusText")
Delay(10)
Wend
result = #True
EndIf
ProcedureReturn result
EndProcedure
;Returns #True if successful.
Procedure.i IE_DownloadComplete()
Protected result = #False, doc.COMateObject
If IE
doc = IE\GetObjectProperty("Document")
If doc
HTML_Txt_Login = doc\GetObjectProperty("All\Item('name')")
If HTML_Txt_Login
HTML_Txt_Pass = doc\GetObjectProperty("All\Item('pass')")
If HTML_Txt_Pass
HTML_Form = doc\GetObjectProperty("Forms('theform')")
If HTML_Form
result = #True
EndIf
EndIf
EndIf
doc\Release()
EndIf
EndIf
ProcedureReturn result
EndProcedure
Procedure Btn_Search_Click()
If HTML_Txt_Login And HTML_Txt_Pass And HTML_Form
HTML_Txt_Login\SetProperty("Value = 'xxxx'")
HTML_Txt_Pass\SetProperty("Value = 'xxxx'")
HTML_Form\Invoke("submit")
EndIf
EndProcedure
Procedure TidyUp()
If HTML_Txt_Login
HTML_Txt_Login\Release()
EndIf
If HTML_Txt_Pass
HTML_Txt_Pass\Release()
EndIf
If HTML_Form
HTML_Form\Release()
EndIf
EndProcedure
Note the TidyUp() function!
If it doesn't work on your https site(s) then I'm afraid that you are on your own.

Posted: Fri Mar 13, 2009 12:21 pm
by Kwai chang caine
Oooohhhh my dear SROD
You are so sweet for me
It's true i don't want to take so much your time
Then KCC have create a new THREAD, like you have say to him, for ask help with another member of forum
http://www.purebasic.fr/english/viewtopic.php?t=36715
I don't know ....but perhaps a new idea of somebody :roll:
Really i thanks you, for your kindness with the poor KCC.
I'm confused, but i don't works today.
KCC is unnerve because he can't try your splendid code
But monday, KCC run at his works, and fall in the staircase, don't say hello at "nobody", fall on his computer, and the first thing he test, it's your code
I thanks you very very much.
And i wish you a very good week end
Works good for to be again more intelligent .....if it's possible obviously :roll:
Your Personal IDIOT, who love you
KCC