Recent

Author Topic: Need Help Adding RichChat Utility to THTMLView (Code Included)  (Read 17586 times)

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #15 on: August 28, 2012, 12:08:56 am »
Hmm, I don't remember solution (I used this control for "chat" program too), but what I always did when I stuck, I set problematic html to method SetHTMLFromStr (in your case "<p>this is link: <a href="http://google.com">Google</a>) and then if this link works and render fine, then I enumarated html nodes and debug which values it is storing (to some memo etc). So then I could set correct values in pascal

Hmm...I can't use SetHTMLFromStr if it clears what is in the chat already.  I guess I'll have to fool around with it.

Do you have any idea how to make the horizontal scrollbar hidden?  When the vertical scrollbar appears, the horizontal one does too, but I only want the vertical one and don't see any options to mess with them.

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #16 on: August 28, 2012, 12:28:51 am »
Hmm...I can't use SetHTMLFromStr if it clears what is in the chat already.  I guess I'll have to fool around with it.
I always had some draft project only for html testing, so I didn't have to mess up code in original code ;)
Quote
Do you have any idea how to make the horizontal scrollbar hidden?  When the vertical scrollbar appears, the horizontal one does too, but I only want the vertical one and don't see any options to mess with them.
This is really strange. All controls of this kind (containers) has Scrollbars property but IpHTMLPanel doesn't has. But this could be some kind of "planned feature". Notice, unlike THTMLPort, TIpHTMLPanel is more related to the HTML syntax (for example, if you want unicode, you must specify it in <head><meta content="charset=UTF-8">, not in TIpHTMLPanel font property). So maybe to disable scrollbars you must use some HTML syntax (just look for TIpHtmlScrollBar class in IpHTML unit, it even has HTML 4.0 scrollbar styles). What force scrollbars in your case? Images? Because in my case, text always fit and breake on control size

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #17 on: August 28, 2012, 02:16:38 am »

Quote
This is really strange. All controls of this kind (containers) has Scrollbars property but IpHTMLPanel doesn't has. But this could be some kind of "planned feature". Notice, unlike THTMLPort, TIpHTMLPanel is more related to the HTML syntax (for example, if you want unicode, you must specify it in <head><meta content="charset=UTF-8">, not in TIpHTMLPanel font property). So maybe to disable scrollbars you must use some HTML syntax (just look for TIpHtmlScrollBar class in IpHTML unit, it even has HTML 4.0 scrollbar styles). What force scrollbars in your case? Images? Because in my case, text always fit and breake on control size

In my case the vertical scrollbars are needed because the color chat is not large and I just keep adding lines to it.  It's like a history log of actions you take in the program and chats with other people you are connected to.  It fills up in likely 20 seconds of use, but you really only need to see the last several actions and chats most of the time.  It's like Internet Relay Chat, with a long history you can scroll up through.

The horizontal scroll bar is not needed, nor do I exceed the horizontal width at all as far as I can tell.  However, when the vertical scroll bar appears the horizontal one also always appears at the same time.

I looked through the unit as you said.  It looks like the scrollbar is accessed via TIpHtmlInternalPanel.HScroll.Visible:=false;?  I'm guessing the TIpHtmlInternalPanel relates to the TIpHtmlPanel somehow, but I'm not sure how.  Any idea how I could access the TIpHtmlInternalPanel from my TIpHtmlPanel so that I could set the HScroll visible to false?

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #18 on: August 29, 2012, 01:17:41 pm »
Hmm, I don't remember solution (I used this control for "chat" program too), but what I always did when I stuck, I set problematic html to method SetHTMLFromStr (in your case "<p>this is link: <a href="http://google.com">Google</a>) and then if this link works and render fine, then I enumarated html nodes and debug which values it is storing (to some memo etc). So then I could set correct values in pascal

I figured out how to create links dynamically.  The order of the nodes is important for this apparently.  I did bodyNode <-- styleNode <-- fontNode <-- linkNode and then the dynamically created links worked fine.  I still haven't figured out the scrollbar issue, though I mentioned a possible clue above.
« Last Edit: August 29, 2012, 01:22:02 pm by evoshroom »

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #19 on: August 29, 2012, 03:05:01 pm »
This is really strange. All controls of this kind (containers) has Scrollbars property but IpHTMLPanel doesn't has. But this could be some kind of "planned feature". Notice, unlike THTMLPort, TIpHTMLPanel is more related to the HTML syntax (for example, if you want unicode, you must specify it in <head><meta content="charset=UTF-8">, not in TIpHTMLPanel font property). So maybe to disable scrollbars you must use some HTML syntax (just look for TIpHtmlScrollBar class in IpHTML unit, it even has HTML 4.0 scrollbar styles). What force scrollbars in your case? Images? Because in my case, text always fit and breake on control size

Well, I couldn't figure out how to do it the nice way, so I just hacked it:

Code: [Select]
constructor TIpHtmlInternalPanel.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := ControlStyle + [csCaptureMouse];
  DragMode := dmManual;
  HScroll := TIpHtmlScrollBar.Create(Self, sbHorizontal);
  HScroll.Tracking := True;

  //INSERTED THIS LINE
  HScroll.Visible := False;

  VScroll := TIpHtmlScrollBar.Create(Self, sbVertical);
  VScroll.Tracking := True;
  HintWindow := THintWindow.Create(Self);
  HintWindow.Color := Application.HintColor;
end;

It prevents the horizontal scrollbar from ever showing.  However, if you ever happen to figure out how to do it without editing the component's code itself, let me know.

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #20 on: August 29, 2012, 05:26:53 pm »
One last issue.  The memory usage seems rather high.  According to my calculations on Mac OS X per line of Richtext added the program uses about 200kb of ram.  That adds up fast, and seems like quite a lot for a single line of colored text.  Am I supposed to be tNode.Free; -ing or anything like that?  I tried it and it caused errors.  Is there a way of reducing the amount of ram it gobbles up?  What could be causing such high ram usage?

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #21 on: August 29, 2012, 06:51:11 pm »
One last issue.  The memory usage seems rather high.  According to my calculations on Mac OS X per line of Richtext added the program uses about 200kb of ram.  That adds up fast, and seems like quite a lot for a single line of colored text.  Am I supposed to be tNode.Free; -ing or anything like that?  I tried it and it caused errors.  Is there a way of reducing the amount of ram it gobbles up?  What could be causing such high ram usage?

One possible solution I thought of to this was to call htmlChat.SetHtmlFromStr( ) periodically and replace all the nodes with a string version of the same data, thereby freeing the nodes.  My own testing seemed to indicate that the same data takes up much less RAM when SetHtmlFromStr() is used, but this cannot be called every line because it results in program lag, which I also tested.  However, it could possibly be called periodically to clear out excess memory used by the nodes.  However, I couldn't find any property to get the HTML in string form.  I also considered trying:

Code: [Select]
htmlChat.SetHtml(htmlChat.MasterFrame.Html);
However, that just causes an error.  Any ideas?  This component performs perfectly apart from the memory overhead.  Anything to keep the memory usage reasonable should allow me to finally move on to non-chat-related programming. :)

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #22 on: August 29, 2012, 08:05:36 pm »
One last issue.  The memory usage seems rather high.  According to my calculations on Mac OS X per line of Richtext added the program uses about 200kb of ram.  That adds up fast, and seems like quite a lot for a single line of colored text.  Am I supposed to be tNode.Free; -ing or anything like that?  I tried it and it caused errors.  Is there a way of reducing the amount of ram it gobbles up?  What could be causing such high ram usage?

I assume you're looking at Activity Monitor to determine this. In my experience, whether you're using Activity Monitor on Mac or Task Manager on Windows, the amount of RAM a running app appears to be using tends to go up the longer you use the app and rarely goes down when you would expect it to (close and free a large form or document, for example). In fact, I'm not sure how useful this measurement is, other than to show large differences between apps or versions, say. For example, Firefox appears to use a staggering amount of RAM and certainly if you've ever seen it hang while downloading a multi-gig file, then it does appear to run out of RAM.

Another example: 3 GIS apps. After startup, without loading any image or shapefile layers, we see this RAM use:

(1) .NET-based GIS: 19MB
(2) wxWidgets-based GIS: 23MB
(3) QT-based GIS: 95MB

(1) and (2) are close, but (3) is so far beyond them that you wonder what's going on. (Well, it's probably all the Qt libraries getting loaded - for example, QtWebKit4.dll alone is over 10MB in size.)

To determine if what you're seeing is due to memory _leaks_, however, you need to profile your app. With Xcode, you would use Instruments. You might be able to start Instruments independent of Xcode and load your app. But if you don't find sizable leaks, then that's not what's going on. Rather, it's probably related to your app's memory manager and its interactions with system memory allocation.

Thanks.

-Phil

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #23 on: August 29, 2012, 08:18:02 pm »
One last issue.  The memory usage seems rather high.  According to my calculations on Mac OS X per line of Richtext added the program uses about 200kb of ram.  That adds up fast, and seems like quite a lot for a single line of colored text.  Am I supposed to be tNode.Free; -ing or anything like that?  I tried it and it caused errors.  Is there a way of reducing the amount of ram it gobbles up?  What could be causing such high ram usage?

I assume you're looking at Activity Monitor to determine this. In my experience, whether you're using Activity Monitor on Mac or Task Manager on Windows, the amount of RAM a running app appears to be using tends to go up the longer you use the app and rarely goes down when you would expect it to (close and free a large form or document, for example). In fact, I'm not sure how useful this measurement is, other than to show large differences between apps or versions, say. For example, Firefox appears to use a staggering amount of RAM and certainly if you've ever seen it hang while downloading a multi-gig file, then it does appear to run out of RAM.

Another example: 3 GIS apps. After startup, without loading any image or shapefile layers, we see this RAM use:

(1) .NET-based GIS: 19MB
(2) wxWidgets-based GIS: 23MB
(3) QT-based GIS: 95MB

(1) and (2) are close, but (3) is so far beyond them that you wonder what's going on. (Well, it's probably all the Qt libraries getting loaded - for example, QtWebKit4.dll alone is over 10MB in size.)

To determine if what you're seeing is due to memory _leaks_, however, you need to profile your app. With Xcode, you would use Instruments. You might be able to start Instruments independent of Xcode and load your app. But if you don't find sizable leaks, then that's not what's going on. Rather, it's probably related to your app's memory manager and its interactions with system memory allocation.

Thanks.

-Phil

Yes, I was looking at activity monitor.  I'm not sure these are leaks.  This may just be node overhead.  I realized later also that I can't free the nodes, because I successfully did so and freeing the nodes makes the HTML that the nodes represented also disappear, as would be expected.  So if you free a brNode the end of line space is then gone.

My app starts out at about 85 mb of usage.  As you keep adding lines, it will keep climbing.  However, if it is at say 160 mb of usage and you do a htmlChat.SetHtmlFromStr( ) it will drop down to 100mb of usage. This is consistent with the idea that the nodes have a heavy RAM overhead, but that when using raw HTML the overhead is less.  Similarly, if sample lines are constructed and added using just htmlChat.SetHtmlFromStr(LongerAndLongerString) the overhead is again reasonable (though the lag is not).

I was considering a hybrid model where I use the nodes and then every couple minutes perhaps refresh the HTML with a string version of itself, clearing out the old nodes and dropping the memory usage back down.  That's the best option I could figure at least.  Now, I could do this the hard way, where I keep a separate version of the line added in a TStringList and then use that to refresh, but it seemed rather hackish and I was wondering if there was any way to pull the HTML in String version directly from a property of the IpHTMLPanel to do so?

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #24 on: August 29, 2012, 08:26:10 pm »
Yes, I was looking at activity monitor.  I'm not sure these are leaks.  This may just be node overhead.  I realized later also that I can't free the nodes, because I successfully did so and freeing the nodes makes the HTML that the nodes represented also disappear, as would be expected.  So if you free a brNode the end of line space is then gone.

My app starts out at about 85 mb of usage.  As you keep adding lines, it will keep climbing.  However, if it is at say 160 mb of usage and you do a htmlChat.SetHtmlFromStr( ) it will drop down to 100mb of usage. This is consistent with the idea that the nodes have a heavy RAM overhead, but that when using raw HTML the overhead is less.  Similarly, if sample lines are constructed and added using just htmlChat.SetHtmlFromStr(LongerAndLongerString) the overhead is again reasonable (though the lag is not).

I was considering a hybrid model where I use the nodes and then every couple minutes perhaps refresh the HTML with a string version of itself, clearing out the old nodes and dropping the memory usage back down.  That's the best option I could figure at least.  Now, I could do this the hard way, where I keep a separate version of the line added in a TStringList and then use that to refresh, but it seemed rather hackish and I was wondering if there was any way to pull the HTML in String version directly from a property of the IpHTMLPanel to do so?

That sounds like an awful lot of RAM. Compare against other apps on your Mac. For example, the Lazarus IDE. Or the THtmlPort FrameDem example.

And what about your app on Windows, say? What do you see there?

Thanks.

-Phil

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #25 on: August 29, 2012, 08:57:26 pm »

That sounds like an awful lot of RAM. Compare against other apps on your Mac. For example, the Lazarus IDE. Or the THtmlPort FrameDem example.

And what about your app on Windows, say? What do you see there?

Thanks.

-Phil

I'm not sure what you are referring to.  The 85 meg is not horrible for my program, as much of it is graphics.  Also, things take up more RAM on a Mac versus Windows.  For comparison, Firefox with one website open takes 180mb of RAM.  Lazarus takes 140mb of RAM.

However, yes, the 160mb usage is obviously extreme.  The program starts at 85 megs and grows roughly 120k per line added.  Each line has at least a style node, a font node, a text node and a br node.  However, if the lines are added via htmlChat.SetHtmlFromStr() the RAM usage grows at a far decreased rate and if SetHtmlFromStr is used post-adding all the nodes, the RAM usage also decreases.

On Windows the program starts out at 33mb of usage, but exhibits the same 120k per node-line added issue.

I'm not really sure where I should go from here, but the RAM usage using the nodes alone is too high. :-/

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Need Help Adding RichChat Utility to THTMLView (Code Included)
« Reply #26 on: August 29, 2012, 09:43:41 pm »
And what about your app on Windows, say? What do you see there?
-Phil

I figured since I already basically wrote a demo app for this thread to start, it wouldn't take more than a few minutes to get it working with IpHTML instead of what I was originally using and modify it a bit.  So I did so.  You can download it from the below link and see the ram issue yourself.  It's a very simple and easy to use demo of both the basic idea of a RichChat and the current problem I'm having with the RAM usage (if you monitor it's RAM with Task Manager or anything else).  If the RAM issue is ever solved it could also function as a good demo for others wanting similar functionality.

http://www.mediamarksman.com/IpHTMLRichChatTest.zip

Check it out!

 

TinyPortal © 2005-2018