# WebCanvas vs WebImageView for generated image with text and graphics 

**URL:** <https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851>\
**Category:** Web\
**Created:** [October 18, 2014, 1:26pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851 "2014-10-18T13:26:56Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Pastor1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Mark\_Pastor1](https://forum.xojo.com/u/Mark_Pastor1)\
**Post date:** [October 18, 2014, 1:26pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/1 "2014-10-18T13:26:56Z")

</div>

Continuing the saga of creating a nice looking list with icons… and there are probably lots of good reasons to not approach it this way - feel free to express those thoughts…

I have a database with user info, one field is a text description which could be any length.

Method 1: I have experimented with expressing this list of descriptions in a canvas, using the g.drawstring command in the paint event of the canvas.  
Method 2: I have also defined a picture property § and expressed the text using p.graphics.drawstring…

In method 1 - the text is updated as I scroll through the database (using verticalscrollbar and code to do so) - however, it doesn’t take long for the program to crash this way - I am suspecting some sort of overload condition that is difficult to recreate in a simple test app without a database. I introduced a timer to do the repaint after things settle down from the scrolling (say refresh after waiting a second) - but it still crashes.  
In method 2 - once I render the first image in the canvas (g.drawpicture p,0,0) in the canvas paint event, I can not seem to get the picture to update when I re-render p, and refresh the canvas - instead the canvas goes blank.

If instead (since I am creating a picture - p) I use a WebImageView and just re-assign WebImageView.Picture = p after every time I re-render the list in p, everything seems to work just fine - it just feels a bit less responsive than Method 1 and the WebCanvas - if only that method didn’t crash.

Any comments or insights on best approach for mixing text from a database and small images in a list like fashion without using 3rd party controls?

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [October 18, 2014, 1:38pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/2 "2014-10-18T13:38:01Z")

</div>

I’d like to know more about the crashes. Can you give some more specifics, like a stack trace?

What many people do is create a list using ContainerControls and adding them with EmbedWithin.

---

<div class="post-metadata">

**Author:** ![Mark\_Pastor1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Mark\_Pastor1](https://forum.xojo.com/u/Mark_Pastor1)\
**Post date:** [October 18, 2014, 1:43pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/3 "2014-10-18T13:43:18Z")

</div>

[quote=136084:@Greg O’Lone]I’d like to know more about the crashes. Can you give some more specifics, like a stack trace?

What many people do is create a list using ContainerControls and adding them with EmbedWithin.[/quote]  
Sure I will do that. When you say using ContainerControls and EmbedWithin - I have done a lot of that as well - using a canvas in the container, but was having a heck of a time getting that to scroll as I wanted it to without a scrollbar. And since I wasn’t scrolling as I wanted, I probably didn’t generate the crash condition.

---

<div class="post-metadata">

**Author:** ![Mark\_Pastor1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Mark\_Pastor1](https://forum.xojo.com/u/Mark_Pastor1)\
**Post date:** [October 18, 2014, 1:57pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/4 "2014-10-18T13:57:53Z")

</div>

> [@136084:@Greg O'Lone](#):
>
> Can you give some more specifics, like a stack trace?

This is the info reported when it crashed - I think this is what you are asking for? I modified some of the confidential contents of the text below. I notice that some of the records are repeating, which I would not expect.

When I initialize the view, I generate a record set (rs). When I move the scroll bar, I move to the appropriate starting record in the record set: rs.MoveFirst, then do loop rs.MoveNext to the appropriate location in the record set (without exceeding eof). So when I move the scroll bar quickly, this crash situation occurs. Even if I delay things via timer as mentioned previously in this thread.

Here is the dump…

Could not execute returned javascript: Unexpected token ILLEGAL  
Source: Xojo.controls[‘TcOUZaUe’].editScript(2,‘context.fillText(\’ Student Fees are in Infinite Campus and may be paid at this time. Click here to learn more. If you have questions about any fee that is listed for your child, please contact the school.

If you have any questions, please contact the school at (555) 555-5555.\‘,40,30);’,8);  
Xojo.controls[‘TcOUZaUe’].editScript(2,‘context.fillText(\‘Piano lessons for xxxxxxxx\’,40,60);’,17);  
Xojo.controls[‘TcOUZaUe’].editScript(2,‘context.fillText(\‘Oil & Gas version of xxxx+xxxxSB\’,40,90);’,26);  
Xojo.controls[‘TcOUZaUe’].editScript(2,‘context.fillText(\‘ROI of Archive Fed Deck for Book of LLLLLLL\’,40,120);’,35);  
Xojo.controls[‘TcOUZaUe’].editScript(2,‘context.fillText(\‘Schedule Eye Appointment 555.555.5555 -why is this here?\’,40,150);’,44);  
Xojo.controls[‘TcOUZaUe’].editScript(2,‘context.fillText(\‘Check in with Jeff llllllllll\’,40,180);’,53);  
Xojo.controls[‘TcOUZaUe’].editScript(2,‘context.fillText(\‘Get an electrician to complete basement\’,40,210);’,62);  
Xojo.controls[‘TcOUZaUe’].editScript(2,‘context.fillText(\‘Barclays Bank Delaware - Master Card\’,40,240);’,71);  
Xojo.controls[‘TcOUZaUe’].editScript(2,‘context.fillText(\‘LLLLLL-X + Software Partner Solution Brief\’,40,270);’,80);  
Xojo.controls[‘TcOUZaUe’].editScript(2,‘context.fillText(\‘Piano Tuner\’,40,300);’,89);  
Xojo.controls[‘TcOUZaUe’].editScript(1,‘context.fillText(\‘Oil & Gas version of LLLLLL+AAAAASB\’,40,30);’,8);  
Xojo.controls[‘TcOUZaUe’].editScript(1,‘context.fillText(\‘ROI of Archive Fed Deck for Book of LLLLLL\’,40,60);’,18);  
Xojo.controls[‘TcOUZaUe’].editScript(1,‘context.fillText(\‘Schedule Eye Appointment 555.555.5555-why is this here?\’,40,90);’,28);  
Xojo.controls[‘TcOUZaUe’].editScript(1,‘context.fillText(\‘Check in with Jeff llllllll\’,40,120);’,38);  
Xojo.controls[‘TcOUZaUe’].editScript(1,‘context.fillText(\‘Get an electrician to complete basement\’,40,150);’,48);  
Xojo.controls[‘TcOUZaUe’].editScript(1,‘context.fillText(\‘Barclays Bank Delaware - Master Card\’,40,180);’,58);  
Xojo.controls[‘TcOUZaUe’].editScript(1,‘context.fillText(\‘LLLLL-X + Software Partner Solution Brief\’,40,210);’,68);  
Xojo.controls[‘TcOUZaUe’].editScript(1,‘context.fillText(\‘Piano Tuner\’,40,240);’,78);  
Xojo.controls[‘TcOUZaUe’].editScript(1,‘context.fillText(\‘Facebook Blu-ray Technology - Blog\’,40,270);’,88);  
Xojo.controls[‘TcOUZaUe’].editScript(1,‘context.fillText(\‘Chiropractor from Race Event - sent email to him on 8.26\’,40,300);’,98);  
Xojo.controls[‘TcOUZaUe’].runScript(23);

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [October 18, 2014, 2:36pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/5 "2014-10-18T14:36:24Z")

</div>

Ok. To be clear, this is not a crash per se, it’s just a bug of some kind. That window will have a note about an Exception if it’s a crash.

I’m guessing that the problem is that the multi-line items are not being escaped properly, but I have no idea why.

As far as the duplicates go, WebCanvas uses a diff algorithm to send new data to the browser in an attempt to speed things up a bit, but if you’re drawing the same text twice in the same event loop, it’ll look just like this.

---

<div class="post-metadata">

**Author:** ![Mark\_Pastor1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Mark\_Pastor1](https://forum.xojo.com/u/Mark_Pastor1)\
**Post date:** [October 18, 2014, 2:38pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/6 "2014-10-18T14:38:48Z")

</div>

[quote=136090:@Greg O’Lone]Ok. To be clear, this is not a crash per se, it’s just a bug of some kind. That window will have a note about an Exception if it’s a crash.

I’m guessing that the problem is that the multi-line items are not being escaped properly, but I have no idea why.[/quote]  
I think this is yours to fix, not mine - right?

---

<div class="post-metadata">

**Author:** ![Mark\_Pastor1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Mark\_Pastor1](https://forum.xojo.com/u/Mark_Pastor1)\
**Post date:** [October 18, 2014, 2:46pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/7 "2014-10-18T14:46:06Z")

</div>

> [@136084:@Greg O'Lone](#):
>
> What many people do is create a list using ContainerControls and adding them with EmbedWithin.

Just to be clear, I have also experimented with a lot of this approach - where a row is a container of controls, and the list is a collection of those rows. I always get that to work well, as long as I don’t try to generate too many rows (causing lots of latency); and yes I can create them in small batches as well. I was just looking for a pure graphics approach which has some appeal for appearances and other factors.

---

<div class="post-metadata">

**Author:** ![Mark\_Pastor1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Mark\_Pastor1](https://forum.xojo.com/u/Mark_Pastor1)\
**Post date:** [October 18, 2014, 2:53pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/8 "2014-10-18T14:53:13Z")

</div>

> [@136090:@Greg O'Lone](#):
>
> I’m guessing that the problem is that the multi-line items are not being escaped properly, but I have no idea why.

I replaced all line endings with " | " and that seems to avoid the ‘crash’.

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [October 18, 2014, 3:17pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/9 "2014-10-18T15:17:35Z")

</div>

> [@136091:@Mark Pastor](#):
>
> I think this is yours to fix, not mine - right?

I’d check the encoding of the data coming out of your database. It’s entirely possible that there’s NO encoding set. I’d make sure they are UTF8.

---

<div class="post-metadata">

**Author:** ![Mark\_Pastor1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Mark\_Pastor1](https://forum.xojo.com/u/Mark_Pastor1)\
**Post date:** [October 18, 2014, 3:35pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/10 "2014-10-18T15:35:25Z")

</div>

> [@136098:@Greg O'Lone](#):
>
> I’d check the encoding of the data coming out of your database. It’s entirely possible that there’s NO encoding set. I’d make sure they are UTF8.

Where is the appropriate place to set these encodings? I hate to admit this is not something I have typically done.

---

<div class="post-metadata">

**Author:** ![Mark\_Pastor1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Mark\_Pastor1](https://forum.xojo.com/u/Mark_Pastor1)\
**Post date:** [October 18, 2014, 3:46pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/11 "2014-10-18T15:46:22Z")

</div>

I am using SQLite - and the language reference says: "SQLiteDatabase converts text to UTF-8 text encoding. "  
So I think that means I am OK - right?

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [October 18, 2014, 9:08pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/12 "2014-10-18T21:08:27Z")

</div>

Still, you should set the encoding when you retrieve it.

RS.field(“name”).stringvalue.defineEncoding(Encodings.UTF8)

---

<div class="post-metadata">

**Author:** ![Mark\_Pastor1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Mark\_Pastor1](https://forum.xojo.com/u/Mark_Pastor1)\
**Post date:** [October 18, 2014, 9:10pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/13 "2014-10-18T21:10:30Z")

</div>

What a pain - lots of code without that already.  
But thanks for the insight.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [October 18, 2014, 9:18pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/14 "2014-10-18T21:18:04Z")

</div>

any time you get data from outside you should use define encoding  
this includes reading from a database, reading a file, serial ports, sockets of all kinds  
NOT doing so leaves yourself open to unexpected handling of what should be “text”

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:27pm UTC](https://forum.xojo.com/t/webcanvas-vs-webimageview-for-generated-image-with-text-and-graphics/19851/15 "2020-10-29T17:27:34Z")

</div>


