As I mentioned in a couple of my other threads, I'm building a control to pretty much replicate the SMS text messaging on the iPhone. This consists of simply a bubble on either side of the control containing text. I already have a working version, but need to re-build it from scratch. I'd like some advice on some things...
What do you think is the best method to store the list of message data? I was thinking using a TCollection, but that could be way too heavy. Currently I'm using a TStringList containing raw text data which is parsed out and translated appropriately. This works great because I don't have to create any extra objects with loads of unnecessary properties. It's just...
Anyway, I expect possibly thousands of messages in this control. Which brings me to my next question. The best way to draw it. Currently, I'm using a TDrawGrid, and am in the process of converting it to a TStringGrid so I can contain the text directly in the grid rather than the TStringList. However that's where I stopped because I'm wondering if there's another better way than to use a grid. It's easy because it automatically manages storing the rect of each cell, etc.
How about using a TImage instead? There's another concern about the largest possible control size. This control automatically grows higher with the more messages, so again, if there's for example 1,000 messages, with an average message bubble height of about 80 pixels, that would mean the grid control needs to be 80,000 pixels high. Using a TImage though could be tough, because I would then have to manually calculate the position on that canvas to draw each balloon, similar to how grids internally keep track of that.
By the way, this grid (or otherwise canvas) is inside of a TScrollBox (final control will inherit from a TScrollingWinControl). This is how it can scroll, while the actual canvas its self is much larger than the control, big enough to draw all the message balloons. Scrolling in the control is actually moving up and down in the TScrollBox to see portions of the control canvas displaying the messages.
To summarize the pieces I need to perfect:
- Light-weight method of storing message items in a list (inside grid, string list, collection, or other list?)
- Scrollable canvas with list items of variable height (grid, image, or other list?)
- Allowing maximum number of messages to be kept with variable heights?
- Ability to customize how the control reacts to user actions to automatically scroll up or down
I'm not necessarily asking for a fix for anything, but rather advice to make it the best possible way. The more input I get, the more I'll be willing to post the final product here in the FAQ!
JD Solutions
What do you think is the best method to store the list of message data? I was thinking using a TCollection, but that could be way too heavy. Currently I'm using a TStringList containing raw text data which is parsed out and translated appropriately. This works great because I don't have to create any extra objects with loads of unnecessary properties. It's just...
Code:
data syntax:
<user_size><deliminator><user><message_size><deliminator><message>
which could look like:
9|djjd4713023|This is a test message!
characters:
SDTTTTTTTTTSSDTTTTTTTTTTTTTTTTTTTTTTT
user_size = 9
deliminator = |
user = djjd47130
etc.......
Anyway, I expect possibly thousands of messages in this control. Which brings me to my next question. The best way to draw it. Currently, I'm using a TDrawGrid, and am in the process of converting it to a TStringGrid so I can contain the text directly in the grid rather than the TStringList. However that's where I stopped because I'm wondering if there's another better way than to use a grid. It's easy because it automatically manages storing the rect of each cell, etc.
How about using a TImage instead? There's another concern about the largest possible control size. This control automatically grows higher with the more messages, so again, if there's for example 1,000 messages, with an average message bubble height of about 80 pixels, that would mean the grid control needs to be 80,000 pixels high. Using a TImage though could be tough, because I would then have to manually calculate the position on that canvas to draw each balloon, similar to how grids internally keep track of that.
By the way, this grid (or otherwise canvas) is inside of a TScrollBox (final control will inherit from a TScrollingWinControl). This is how it can scroll, while the actual canvas its self is much larger than the control, big enough to draw all the message balloons. Scrolling in the control is actually moving up and down in the TScrollBox to see portions of the control canvas displaying the messages.
To summarize the pieces I need to perfect:
- Light-weight method of storing message items in a list (inside grid, string list, collection, or other list?)
- Scrollable canvas with list items of variable height (grid, image, or other list?)
- Allowing maximum number of messages to be kept with variable heights?
- Ability to customize how the control reacts to user actions to automatically scroll up or down
I'm not necessarily asking for a fix for anything, but rather advice to make it the best possible way. The more input I get, the more I'll be willing to post the final product here in the FAQ!
JD Solutions