Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Shell.explorer.2 create document from variable
Message
From
27/06/2018 10:55:28
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Application:
Web
Miscellaneous
Thread ID:
01660900
Message ID:
01660911
Views:
1059
This message has been marked as a message which has helped to the initial question of the thread.
My preference is to Navigate2('about:blank'), get the document object and then write to it (I can also use document.Methods to create the DOM programmatically - which is very fast IMHO). Below is a sample code, I have included much more than needed just for sampling different aspects:
Public oForm
oForm = Createobject('form1', GetHTML())
oForm.Show()

Function GetHTML
Local myVar
TEXT to myVar noshow
<html>
<head>
<style>
    .WithBreaks 		{ word-wrap:break-word; background-color:gainsboro; width:100% }
</style>
<title>New User Sign Up</title>
</head>
<body bgcolor=Moccasin>
<h1 align="Center"><font color="#000080">New User Sign Up</font></h1>
<form method="GET" action="empty.htm" target="_self" name="myForm">
  <table border="0" cellspacing="1">
    <tr><td>Student ID</td><td><input type="text" name="ID" maxlength="16"></td></tr>
    <tr><td>First Name</td><td><input type="text" name="First" maxlength="15"></td></tr>
    <tr><td>Last Name</td><td><input type="text" name="Last" maxlength="20"></td></tr>
	<tr>
   <td>Gender?</td>
   <td>
     <select name="pro1">
       <option value=0>- Gender? -</option>
       <option value=116>Female</option>
       <option value=115>Male</option>
     </select></td></tr>
<tr>
   <td>Ethnic Background?</td>
   <td width = 40px>
     <select name="pro2" onactivate='this.style.width = "400px";' ondeactivate='this.style.width = this.parentElement.width;' >
       <option value="0">- Ethnic Background? -</option>
       <option value="121">American Indian or Alaskan Native</option>
       <option value="120">Asian or Pacific Islander</option>
       <option value="118">Black-Non Hispanic</option>
       <option value="119">Hispanic</option>
       <option value="122">Non-Resident</option>
       <option value="117">White-Non Hispanic</option>
     </select></td>
</tr>
	</table>
  <p>  <A href="newproc">Click to submit</a>  <p>
<input type=submit name=sub1 value="Write" onclick='document.all("submitter").value=1;'>
<input type=submit name=sub2 value="Update" onclick='document.all("submitter").value=2;'>
<input type=submit name=sub3 value="Clear" onclick='document.all("submitter").value=3;'>
</form>
<input type=hidden name="submitter" value=0>


<P>This example shows the <SPAN class="clsLiteral">break-word</SPAN> value of the <B>wordWrap</B> property.</P>

<P CLASS="WithBreaks">LongWord LongWord LongWord LongWord LongWord LongWord LongWord LongWord LongWord LongWord LongWord LongWord LongWord LongWord LongWord LongWord </P>

<P>This example shows the <SPAN class="clsLiteral">normal</SPAN> value of the <B>wordWrap</B> property.</P>


</body>
</html>
ENDTEXT
Return myVar

Define Class HTMLViewer As OleControl
	OleClass = 'Shell.Explorer'

	Procedure Refresh
	Nodefault
	Endproc

	Procedure LoadHTML(tcHTML)
	With This
		.navigate2("about:blank")
		.Document.Write(m.tcHTML)
	Endwith
Enddefine

Define Class form1 As Form
	Height = 470
	Width = 740
	Caption = "HTML sample"

* This is IE control - you'd use webbrowser4 from gallery instead
* just because it already has some checks, extra pem. ie: wouldn't need readystate part
* for the sake of keeping code short here I directly use olecontrol itself
	Add Object HTMLViewer As HTMLViewer With ;
		Top = 12, ;
		Left = 12, ;
		Height = 396, ;
		Width = 708, ;
		Visible = .T., ;
		Anchor = 15, ;
		Name = "HTMLViewer"

	Add Object cmdGetValue As CommandButton With ;
		Height = 25, ;
		Left = 10, ;
		Top = 432, ;
		Width = 100,;
		Anchor = 4, ;
		Caption = 'Get 2 Values'
	Add Object cmdSetValue As CommandButton With ;
		Height = 25, ;
		Left = 130, ;
		Top = 432, ;
		Width = 100,;
		Anchor = 4, ;
		Caption = 'Set 2 Values'

	Procedure Init
	Lparameters tcHTML
	With Thisform.HTMLViewer
		.LoadHTML(m.tcHTML)
	Endwith
	Endproc

	Procedure cmdGetValue.Click
	TEXT TO result TEXTMERGE noshow
	Pro 1:
	<<thisForm.htMLVIEWER.object.Document.all('pro1').Value>>
	Pro 2:
	<<thisForm.htMLVIEWER.object.Document.all('pro2').Value>>
	ENDTEXT
	Messagebox(m.result)
	Endproc

	Procedure cmdSetValue.Click
	Thisform.HTMLViewer.Object.Document.All('pro1').Value = 115
	Thisform.HTMLViewer.Object.Document.All('pro2').Value = 119
	Endproc

	Procedure HTMLViewer.NavigateError
	Lparameters pdisp, url, frame, statuscode, Cancel
	Set Step On
	Cancel = .T.
	Endproc

	Procedure HTMLViewer.BeforeNavigate2
	Lparameters pdisp, url, Flags, targetframename, postdata, headers, Cancel
	TEXT to m.lcParamList textmerge noshow
  pdisp = pdisp
  url = <<url>>
  flags = <<flags>>
  targetframename = <<targetframename>>
  postdata = <<postdata>>
  headers = <<headers>>
  Cancel = <<Cancel>>
	ENDTEXT
	Messagebox(m.lcParamList)

*  oFrm = This.Object.Document.myForm
	lcVals = ""
	If This.Object.Document.Forms.Length > 0
		For Each oFrm In This.Object.Document.Forms
			lcVals = lcVals + oFrm.Name + Chr(13)
			If oFrm.elements.Length > 0
				For Each oElem In oFrm.elements
					If oElem.Type = "select-multiple"
						lcList=''
						For ix=0 To oElem.Length-1
							If oElem.Item(ix).Selected
								lcList = lcList + Iif(Empty(lcList),'',',')+oElem.Item(ix).Value
							Endif
						Endfor
						lcVals = lcVals + "Name :" + oElem.Name + "/Value:"+lcList + Chr(13)
					Else
						lcVals = lcVals + "Name :" + oElem.Name + "/Value:"+oElem.Value + Chr(13)
					Endif
					oElem = .Null.
				Endfor
			Endif
			oFrm = .Null.
		Endfor
	Endif
	Cancel = .T.  && prevents actual navigation
	lcVals = lcVals + Chr(13)+Chr(10)+'Submitted by:'+Transform(This.Object.Document.All("submitter").Value)
	Messagebox(lcVals)
	Endproc

	Procedure HTMLViewer.Refresh
	Nodefault
	Endproc
Enddefine
HTH
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform