Question about the chat demo

General TRichView support forum. Please post your questions here
Post Reply
cakk
Posts: 14
Joined: Thu Dec 17, 2009 2:35 am

Question about the chat demo

Post by cakk »

I download the chat demo at :

Advanced demo with rich text text input
http://www.trichview.com/support/files/ ... ysiwyg.zip

and it works fine. But I have 2 questions about it:

1.Why the HScrollVisible and VScrollVisible of rv have no effect? I set them to True, but the scrollbar is still hidden. Just when the text too long to going to scroll, it is showing. How can I set the scrollbar visible always, even if the text is empty?

2.How can I made the rv support "returns"? When I paste multi-line text into rve, and click "send", then the text will show in rv, but all of return(CRLF) are missing.

Thanks!
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

1) If *ScrollVisible=True, scrollbars are displayed only when necessary.
If they are False, scrollbars are never displayed.
TRichView has no mode for displaying scrollbars when they are not necessary (unlike TRichViewEdit that always displays vertical scrollbar).

2) This demo inserts ' | ' instead of line breaks. You can see the code in TForm1.Encode:

Code: Select all

    if (i>0) and rve.IsFromNewLine(i) then
      Result := Result +' | ';
How to support line breaks.
a) Exclude rvoDoNotWantReturns from rve.EditorOptions.
In FormCreate, change the assignment to rve.EditorOptions:

Code: Select all

  rve.EditorOptions := rve.EditorOptions+[rvoNoImageResize]-
    [rvoDoNotWantReturns,rvoWantTabs];
b) Change rve.OnKeyDown to send message on Ctrl+Return instead of Return:

Code: Select all

procedure TForm1.rveKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  ...
  if (Key=VK_RETURN) and (Shift=[[color=red]ssCtrl[/color]]) and (rve.InplaceEditor=nil) then begin
    btnEnterClick(nil);
    Key := 0;
  end;
end;
c) Change TForm1.Encode to insert #13 instead of ' | ':

Code: Select all

    if (i>0) and rve.IsFromNewLine(i) then
      Result := Result +[color=red]#13[/color];
d) Change TForm1.ParseString:

Code: Select all

  ...
  for i := 1 to Length(s) do [color=red]begin
    if s[i]=#13 then begin
      AddStringWithURLs(StartIndex, i-1);
      ParaNo := 0;
      ReadState := rsNormal;
      StartIndex := i+1;
      continue;
    end[/color];
    if i>=StartIndex then
      case ReadState of
        ...
      end;
  [color=red]end;[/color]
  AddStringWithURLs(StartIndex, Length(s));
end;
Empty lines will still not be inserted. But I think this is good, because it prevents flooding.
cakk
Posts: 14
Joined: Thu Dec 17, 2009 2:35 am

Post by cakk »

ok! its works fine!! Thanks a lots! :P
Post Reply