Recent

Author Topic: scrolling Tmemos simultaneously ?  (Read 3090 times)

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: scrolling Tmemos simultaneously ?
« Reply #45 on: October 08, 2024, 10:52:45 am »
Here is another approach, operate the second TMemo in mock virtual mode.  No scroll bars, just, apparently, a window into the first TMemo.

The second one, refreshed as the first changes, shows only as much translation as can fit, starting with the first visible content in from the first. I am assuming here that end user only edits first Memo.

Not sure if TMemo tells us what the visible content is so, might need to use a more advanced memo such as KMemo. 

(cannot try it, not typing well after some very minor hand surgery)

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1180
Re: scrolling Tmemos simultaneously ?
« Reply #46 on: October 08, 2024, 01:35:39 pm »
Even though the op asked how to get two memos to scroll together I sort of think it’s our duty to advise them about better alternatives.
I really don’t think that memos are the correct way to do this although it makes an interesting puzzle. The main problem is that memos are imprecise. The memo doesn’t know what the text is for.

If this was my problem I would use an editable string grid with two columns and no headers with grid lines hidden. That would scroll. And look better and there would be no ambiguity about what text belongs together.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

MarkMLl

  • Hero Member
  • *****
  • Posts: 7884
Re: scrolling Tmemos simultaneously ?
« Reply #47 on: October 08, 2024, 01:49:14 pm »
Even though the op asked how to get two memos to scroll together I sort of think it’s our duty to advise them about better alternatives.
I really don’t think that memos are the correct way to do this although it makes an interesting puzzle. The main problem is that memos are imprecise. The memo doesn’t know what the text is for.

OTOH it's a standard control, which counts for quite a lot: you can potentially give the project to anybody without having to tell them "Oh, and you'll need to download this and rebuild your IDE..." which can be incredibly offputting.

Quote
If this was my problem I would use an editable string grid with two columns and no headers with grid lines hidden. That would scroll. And look better and there would be no ambiguity about what text belongs together.

But the two columns need to scroll independently, and my experience using stringgrids for e.g. status message output is that they're at least as fiddly as TMemo/TRichMemo.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

VisualLab

  • Hero Member
  • *****
  • Posts: 518
Re: scrolling Tmemos simultaneously ?
« Reply #48 on: October 08, 2024, 02:46:34 pm »
<cut>...<cut/> The memo doesn’t know what the text is for.

In more complex applications, controls such as TMemo often act as views. And views are supposed to display data and respond to events (e.g. mouse and keyboard). The content should be stored by the model (container). The controller, on the other hand, should know what the data is for, order data processing, and pass it to various views.

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1180
Re: scrolling Tmemos simultaneously ?
« Reply #49 on: October 09, 2024, 12:41:53 am »
I guess it understands key pressing events . Do you have any examples of how views are used ?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

MarkMLl

  • Hero Member
  • *****
  • Posts: 7884
Re: scrolling Tmemos simultaneously ?
« Reply #50 on: October 11, 2024, 04:00:25 pm »
Joanna, in a different thread you've just said

Hi , while you are all busy interacting with this reincarnated poster from  previous equally ridiculous threads, I was trying to build a community for pascal programmers. I believe that aruna invited you to come visit. It’s very easy. You don’t even need an an account. Just come take a quick peek . If you don’t like it you can leave. Can you spare 30 seconds ?

This is why:

Please stop stalking me !  :o

If I had reason to believe that we were in the same legal jurisdiction I would be doing something about that. You do /not/ make that sort of accusation at people and then try to brush it under the carpet. Understand?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 7884
Re: scrolling Tmemos simultaneously ?
« Reply #51 on: October 12, 2024, 12:01:50 am »
Markml You took my reply to the grumpy person (not you) who follows me around to different threads for the sole purpose of telling me to stfu completely out of context.

I didn’t accuse you of stalking!. If I was going to accuse you of something it would be verbal abuse and defamation of character. However when you’re not in a foul mood I actually enjoy talking to you about technical stuff. The stalkier has never had any interest in having technical discussions with me. It just pops up in threads where I’m talking and thanks to faulty forum software I’m not allowed to ignore it.

Bit late for that Joanna.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Aruna

  • Sr. Member
  • ****
  • Posts: 494
Re: scrolling Tmemos simultaneously ?
« Reply #52 on: October 14, 2024, 04:43:40 am »
I would like two Tmemos to scroll simultaneously  ( to move in a text and a translation ).
<snip> ...
P.S. Target are windows and linux, but just one platform would already be good help.
Hello Etienne_L,

This might be a bit late, but I hope it helps. I've attached a zip file with a fully functional proof of concept demo. Give it a try!  It does what you want to do!

Just keep in mind, as dbanon mentioned, translations can quickly get out of sync. What I've implemented will work smoothly as long as the text in both Memos is identical. After you've tested it and confirmed that both Memos scroll synchronously (try tabbing between the two while scrolling), try changing the text or using an actual translation, and you'll notice things starting to misalign.

For those having difficulty with zip files the source code is below:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LMessages,
  9.   ExtCtrls;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Memo1: TMemo;
  17.     Memo2: TMemo;
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure Memo1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  20.     procedure Memo2KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  21.   private
  22.  
  23.   public
  24.  
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. { TForm1 }
  35.  
  36. procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  37. begin
  38. //  writeln('Caret position in Memo1: ', Memo1.SelStart);
  39.   Memo2.SelStart := Memo1.SelStart;
  40.   Memo1.SelStart := Memo2.SelStart;
  41.  
  42. end;
  43.  
  44. procedure TForm1.FormCreate(Sender: TObject);
  45. begin
  46. //  Memo1.Lines.AddStrings(['1','2','3','Etienne_L', 'wizzwizz4', 'Joanna','MarkMLl','TRon','VisualLab','dbannon','ArtLogi','jamie','JanRoza','carl_caulkett','LV']);
  47. //  Memo2.Lines.AddStrings(['1','2','3','Etienne_L', 'wizzwizz4', 'Joanna','MarkMLl','TRon','VisualLab','dbannon','ArtLogi','jamie','JanRoza','carl_caulkett','LV']);
  48. end;
  49.  
  50. procedure TForm1.Memo2KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  51. begin
  52.    Memo1.SelStart := Memo2.SelStart;
  53.    Memo2.SelStart := Memo1.SelStart;
  54. end;
  55.  
  56. end.

At least now you have a starting boiler-plate. This should work across Linux and Windows. I tested on Linux Debian+gtk.
Good luck and hope this will help. Screenshot is attached.
« Last Edit: October 14, 2024, 04:48:26 am by Aruna »

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: scrolling Tmemos simultaneously ?
« Reply #53 on: October 14, 2024, 11:03:20 am »
nice one !

D
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Aruna

  • Sr. Member
  • ****
  • Posts: 494
Re: scrolling Tmemos simultaneously ?
« Reply #54 on: October 14, 2024, 01:12:45 pm »
nice one !
Haha, you like it? It was tricky at first because though the scrolling and syncing worked, the active lines wouldn’t line up properly. They didn’t align horizontally at the same line number or position. Ugh, I’m terrible at explaining things. Let’s try it this way, alright? Comment out the highlighted lines and test again.

Code: Text  [Select][+][-]
  1. procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  2. begin
  3.   Memo2.SelStart := Memo1.SelStart;
  4.   Memo1.SelStart := Memo2.SelStart; <--- Davo COMMENT OUT THIS LINE PLEASE
  5.  
  6. end;
  7.  
  8. procedure TForm1.Memo2KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  9. begin
  10.    Memo1.SelStart := Memo2.SelStart;
  11.    Memo2.SelStart := Memo1.SelStart; <--- Davo COMMENT OUT THIS LINE AS WELL PLEASE
  12. end;
  13.  
« Last Edit: October 14, 2024, 01:19:01 pm by Aruna »

Aruna

  • Sr. Member
  • ****
  • Posts: 494
Re: scrolling Tmemos simultaneously ?
« Reply #55 on: October 14, 2024, 01:15:54 pm »
Aruna i think AI has failed you... :D
Haha, maybe it just had an off moment! But hey, I’m still here, ready to help  8-) I wrote that all by myself AI had nothing to do with this one  :D

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1180
Re: scrolling Tmemos simultaneously ?
« Reply #56 on: October 14, 2024, 01:28:56 pm »
Can you explain how it works?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Aruna

  • Sr. Member
  • ****
  • Posts: 494
Re: scrolling Tmemos simultaneously ?
« Reply #57 on: October 14, 2024, 04:03:07 pm »
Can you explain how it works?
Hello Joanna, These procedures are meant to synchronize the caret positions of two memo components (Memo1 and Memo2) when the user types in either one.

So ..
Code: Pascal  [Select][+][-]
  1. Memo1KeyUp: When the user types in Memo1, the caret position (SelStart) of Memo2 is updated to match Memo1's caret position.

And..
Code: Pascal  [Select][+][-]
  1. Memo2KeyUp: Similarly, when the user types in Memo2, the caret position of Memo1 is updated to match Memo2.

« Last Edit: October 14, 2024, 04:04:40 pm by Aruna »

LV

  • Full Member
  • ***
  • Posts: 134
Re: scrolling Tmemos simultaneously ?
« Reply #58 on: October 14, 2024, 06:24:22 pm »
@Aruna. Very good.
But I noticed some problems:
1. No editing option (pasting from keyboard or clipboard).
2. If you add ScrollBars, they don't sync.

I still think TSynEdit is more suitable for the OP task.
For lovers of John Keats's poetry (see appendix)  O:-)

Updated: I tested on Windows11 and Linux Debian+gtk2
« Last Edit: October 14, 2024, 07:51:15 pm by LV »

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1180
Re: scrolling Tmemos simultaneously ?
« Reply #59 on: October 16, 2024, 09:47:11 am »
I guess I envisioned the memos being scrolled with a vertical scroll bar not being navigated with key presses. Also this would only be sensible if both memos have the same number of strings and are read only.

If the text in one memo becomes longer than the other {from editing one of the memos} it is no longer possible to synchronize them.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

 

TinyPortal © 2005-2018