I have this piece of code where I would like to go to the bottom position if new messages have been loaded ( when AScroll = true ) but it doesn't position ...it only shows me a part of the messages ...then as soon as I use the mouse wheel to scroll then the others appear.
How can I “force” the update after loading the new messages ?
I have FNCCHAT 1.0.6.1
thanks
procedure TframeCHAT.LoadConversation( ANumero: string );
begin
chat.BeginUpdate;
chat.ChatMessages.Clear;
MemoryTableReset( mmMSG );
var AScroll := false;
try
AScroll := LoadNewMessage;
finally
chat.EndUpdate;
if AScroll then
chat.ScrollToBottom;
end;
end;
The chat messages have a dynamic height by default based on the text inside them. To reduce loading times, only part of the items are calculated beforehand, but this comes with the side effect of not knowing where to scroll exactly. We'll look into the possibility of optionally precalculating all items to resolve this.
Currently, there aren't many options for temporary workarounds. To be able to use ScrollToBottom, you'd need to set the Appearance.Spacing to 0 and the ItemAppearance.HeightMode to tvhmFixed programmatically, but this will result in a look that won't allow any time stamps.
Alternatively, you can scroll to each message individually to force the calculation but depending on the number of messages, this will likely result in performance issues.
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
itm: TTMSFNCChatItem;
begin
TMSFNCChat1.BeginUpdate;
try
TMSFNCChat1.ChatMessages.Clear;
for I := 0 to 29 do
begin
TMSFNCChat1.AddMessage('Message ' + I.ToString);
end;
finally
TMSFNCChat1.EndUpdate;
for I := 0 to TMSFNCChat1.ChatMessages.Count - 1 do
TMSFNCChat1.ScrollToItem(I);
end;
end;
Starting from the next version you'll find a new PrecalculateItems property in TTMSFNCChat. If you enable that, all items will be calculated whenever the item list is (re)built allowing ScrollToBottom to function correctly.