Recent

Author Topic: Anyone using TKMemo?  (Read 4121 times)

snorkel

  • Hero Member
  • *****
  • Posts: 817
Anyone using TKMemo?
« on: December 09, 2015, 10:21:05 pm »
I am trying to convert a Delphi app that uses trichview and I need to append a stream from one TKmemo to the other.
The control has a loadfromstream that will append if the index param is set to 0, but it's appending at the top and not at the bottom.

If I change the index to -1 it replaces the contents vs appending.   
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: Anyone using TKMemo?
« Reply #1 on: December 09, 2015, 11:55:11 pm »
Using the size of the existing data as a parameter when appending should work?

I tried this code and it seems to work, but I used the same stream the whole time though, so I can't really see if data is added before or after.

Code: Pascal  [Select][+][-]
  1. kmFullText.LoadFromRTFStream(Stream, 0);
  2. Stream.Position:=0;
  3. kmFullText.LoadFromRTFStream(Stream, Stream.Size);
  4.  
« Last Edit: December 10, 2015, 01:28:18 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Anyone using TKMemo?
« Reply #2 on: December 10, 2015, 08:00:39 pm »
Yep, I did that as well, the problem is the stream is inserted at the top.
The solution that TK gave me was to use Kmemo1.selectablelength-1 as the index.

Code: Pascal  [Select][+][-]
  1. kmemo1.LoadFromRTFStream(Stream, Kmemo1.selectablelength-1);

I just need to figure out how to make it scroll to the end like a log window or chat form would do.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Anyone using TKMemo?
« Reply #3 on: December 11, 2015, 05:46:19 am »
To make kmemo scroll to the end do:

Code: Pascal  [Select][+][-]
  1. kmemo1.ExecuteCommand(TKEditCommand.ecEditorBottom);
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Anyone using TKMemo?
« Reply #4 on: December 11, 2015, 05:51:36 am »
I also found I can load a stream that contains kmemo RTF into a table cell like this:
i.e. use a hidden tkmemo to load the stream, then assign the blocks from the hidden kmemo to the table cell.

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.Button1Click(Sender: TObject);
  3. var
  4.   tbl:TKMemoTable;
  5.   textblock:TKMemoTextBlock;
  6.  
  7. begin
  8.   kmemo1.clear;
  9.   kmemo2.Blocks.LockUpdate;
  10.   try
  11.       //add some text to hidden kmemo
  12.       textblock:=kmemo1.Blocks.AddTextBlock('dfdfdfdf',0);
  13.       textblock.TextStyle.Font.color:=clred;
  14.       textblock.TextStyle.Font.Style:=[fsbold];
  15.       //add a table to visible kmemo
  16.       tbl:=kmemo2.Blocks.AddTable(0);
  17.       tbl.ColCount:=3;
  18.       tbl.RowCount:=1;
  19.  
  20.       tbl.CellStyle.BorderWidth:=1;
  21.       //add some text to first cell
  22.       tbl.Cells[0,0].Blocks.AddTextBlock('dfdfdfdf');
  23.       //add the contents of the hidden kmemo to the second cell
  24.       tbl.Cells[1,0].Blocks.Assign(kmemo1.Blocks);
  25.       //clear the hidden kmemo
  26.       kmemo1.clear;
  27.       tbl.ApplyDefaultCellStyle;
  28.  
  29.   finally
  30.       kmemo2.Blocks.UnLockUpdate;
  31.   end;
  32.   //scroll to bottom
  33.   kmemo2.ExecuteCommand(TKEditCommand.ecEditorBottom);
  34.  
  35. end;              
  36.  
  37.  
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

 

TinyPortal © 2005-2018