You can change the font and styling of a label with the ide using the inpector panel on the right. Just change tabs at the top (one is a cog and I can’t recall the other icon from my mobile here)
The solution I posted above seems to fail intermittently.
I tried a few things, ended up with the code below in the current version.
This code is called many times within a session. If it works on first call it works every time, but 1 of every 8-10 sessions the display is blank (and continues to be after multiple calls).
Curiously, changing the font size to something smaller makes it [almost] reliably fail…
Overall I’m thinking the HTMLviewer feels like a half-baked piece of RealBasic?
Any thoughts for where to troubleshoot? Intermittent problems are the hardest!
dim htmlText as string
dim f as FolderItem = GetTemporaryFolderItem
htmlText = "<html><head></head><body>"
htmlText = htmlText + "<span style=line-height:1.5em;font-family:Helvetica;font-size:12pt>"
htmlText = htmlText + TargText(port(currentIndex)) + "</span></body></html>"
TargetHTML.Invalidate
TargetHTML.LoadPage(htmlText,f)
TargetHTML.Visible = true
BacktoMainCanvas.Visible = true
Using RealStudio 2011 Release 4.1. Lots of legacy code was reused in other parts of this project, and I’d rather not convert to Xojo (and buy a new license) for this one project…
[quote=226745:@Tamar Kornblum]The solution I posted above seems to fail intermittently.
I tried a few things, ended up with the code below in the current version.
This code is called many times within a session. If it works on first call it works every time, but 1 of every 8-10 sessions the display is blank (and continues to be after multiple calls).
Curiously, changing the font size to something smaller makes it [almost] reliably fail…
Overall I’m thinking the HTMLviewer feels like a half-baked piece of RealBasic?
Any thoughts for where to troubleshoot? Intermittent problems are the hardest!
dim htmlText as string
dim f as FolderItem = GetTemporaryFolderItem
htmlText = "<html><head></head><body>"
htmlText = htmlText + "<span style=line-height:1.5em;font-family:Helvetica;font-size:12pt>"
htmlText = htmlText + TargText(port(currentIndex)) + "</span></body></html>"
TargetHTML.Invalidate
TargetHTML.LoadPage(htmlText,f)
TargetHTML.Visible = true
BacktoMainCanvas.Visible = true
Using RealStudio 2011 Release 4.1. Lots of legacy code was reused in other parts of this project, and I’d rather not convert to Xojo (and buy a new license) for this one project…[/quote]
I doubt extremely much HTMLViewer is to blame. It is a very basic HTML code. I would rather be inclined to suspect some bug in the way TargText(port(currentIndex)) is initialized. You could verify it with a small static symbol in the HTML, for instance a comma immediately after , which will show even if the rest of the text is not there.
[quote=226749:@Norman Palardy]should this be
htmlText = htmlText + “<span style=”“line-height:1.5em;font-family:Helvetica;font-size:12pt”">"
so the styling is a quoted string[/quote]
Good catch. With single quotes it works as well, and is a bit easier on the eyes :
Updated span style as per Michel’s suggestion. Good catch, Norman!
Tried Norman’s suggestion to run with literal. Issue did NOT occur after a number of tries. Interesting…
Added line to catch error, with breakpoint on MsgBox line:
[code] dim htmlText as string
dim f as FolderItem = GetTemporaryFolderItem
htmlText = “”
htmlText = htmlText + “”
htmlText = htmlText + TargText(port(currentIndex)) + “”
if len(htmlText)<125 then 'actual length of html code is 115 characters
MsgBox "Error loading passage text.
end if
TargetHTML.Invalidate
TargetHTML.LoadPage(htmlText,f)
TargetHTML.Visible = true
BacktoMainCanvas.Visible = true [/code]
Issue occurred, but no Message Box or breakpoint! So it seems it’s loading all the content of htmlText correctly?
I think it’s something with how the htmlViewer rendering or visibility. Curiously, when I played around adding or “-” to the end of the htmlText, sometimes the text would not wrap to it’s container, or show up a few lines vertically displaced (the first visible line was line 3 of text, and I couldn’t scroll up.
Is there any way to confirm that the rendered html is in the correct position within the htmlViewer? Or to confirm where the text wrap is? I noticed the wrap issue in the past but it occurred even less frequently than the disappearing text issue…
[quote=229379:@Tamar Kornblum]Issue still persists, here’s the latest:
[/quote]
Which issue exactly ?
If I use your code with a sample text file, spacing is conformant to the HTML, and wrapping occurs as expected. However, you still need to insert line breaks where EndOfLine appear in the text.
Major issue: intermittently, htmlViewer display is completely blank. The container (blank white square) appears and disappears as expected, but NO text shows up.
This is consistent within a session. Each time I run the program, either the text displays correctly every time, or doesn’t display at all.
When I try to debug and add “-” or , I notice intermittent formatting problems (such as text wrap). But the intended text to be displayed is one contiguous paragraph so I can avoid the EOL issues for now.
This is mostly confusing because of how intermittent it is. Sometimes I get 8, 10, or up to 15 sessions with no problems. I’m trying to catch a breakpoint when the error happens to see what’s going on, but my attempt above failed to catch it.
Would it be helpful for me to include a link to the full project? Should I create a separate forum thread? Thanks for your attention!
I will repeat my previous post. You want to check if HTML actually displays something.
You could add to your code :
system.debuglog(TargText(port(currentIndex)))
So when it does not display, you can check in the console on Mac or DebugView on PC that the text is present.
Alternatively, this in a button will display in a MsgBox the content of the HTMLViewer DOM (except ) :
Sub Action()
dim js as string
js = js + "var html = document.getElementsByTagName('HTML')[0].innerHTML; "
js = js + "document.title = html"
TargetHTML.ExecuteJavaScript(js)
End Sub
Would love to see the DOM. Where/how exactly should I use your awesome code?
Also, I tried using system.debuglog(), but seems to not work with my version/OS. I put a simple message in a button, and pushing multiple times adds the following to Console only once per session:
[quote=229549:@Tamar Kornblum]Would love to see the DOM. Where/how exactly should I use your awesome code?
Also, I tried using system.debuglog(), but seems to not work with my version/OS. I put a simple message in a button, and pushing multiple times adds the following to Console only once per session:[/quote]
Re-read my post. The code goes into the Action event of a button.
Sub Action()
dim js as string
js = js + "var html = document.getElementsByTagName('HTML')[0].innerHTML; "
js = js + "document.title = html"
TargetHTML.ExecuteJavaScript(js)
End Sub
Then you get the result in the TitleChanged event of the HTMLViewer, in the newTitle string parameter.
As for System.Debuglog, what you posted has no relationship whatsoever with what you should see.
System.debuglog "Hello World"
Here is what it does in Console :
11/14/15 7:39:35.000 AM My Application.debug[1435]: Hello World
You can also see the same message in the message pane of the IDE when run, which you access by pressing the third icon at the bottom of the central pane of the IDE.
I’m not sure what button you’re referring to. Do I add an object to the HTMLviewer? If so, please include details. I’d love to try it.
To be clear, even when the text is not shown in the HTMLviewer, I’ve confirmed that the html I’m sending is complete even when text doesn’t appear. (copied htmlText variable to window property)
Regarding the console.log - what I pasted above is every line that appears with the identifier of MyApplication.debug. The first line indicates a version mismatch, and after some research I suspect that my version of RealStudio may be too old to play nicely with Console. My IDE doesn’t have a Message pane; that came in a later version.
I created a standalone app with just an HTMLviewer, and copied affected code into it. Each test seems to work perfectly. Perhaps another piece of my project is causing a conflict. Something with how the window opens, or how the control is initiated?
More clues:
sometimes the text appears as one line with no text wrap. This usually happens 1st run after making a minor change in the code.
overall, the disappearing text issue is getting more frequent. Nothing else has changed in the code except for attempts to fix this (removing extra controls, moving code out of KeyDown into a method… all superficial).
Any more ideas for where to look/troubleshoot? The only other activity I have going on during this is a visible countdown timer.
[quote=229977:@Tamar Kornblum]Regarding the console.log - what I pasted above is every line that appears with the identifier of MyApplication.debug. The first line indicates a version mismatch, and after some research I suspect that my version of RealStudio may be too old to play nicely with Console. My IDE doesn’t have a Message pane; that came in a later version.
[/quote]
Please simply look in the Messages pane of the IDE (third icon at the bottom of the central pane).