Recent

Author Topic: Memo Question(Solved)  (Read 604 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1213
Memo Question(Solved)
« on: October 01, 2022, 06:51:26 pm »
There is a Memo1 on Form1. The user edits the Memo. Is there a way to detect the edit. I don't need to know what was edited just that an edit occurred so a save of the memo can occur on exit of the memo.

Thanks.
« Last Edit: October 01, 2022, 09:59:17 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Arioch

  • Sr. Member
  • ****
  • Posts: 414
Re: Memo Question
« Reply #1 on: October 01, 2022, 06:55:22 pm »
TMemo.OnChange ?

Bart

  • Hero Member
  • *****
  • Posts: 4819
    • Bart en Mariska's Webstek
Re: Memo Question
« Reply #2 on: October 01, 2022, 06:59:37 pm »
Memo1.Modified?

Thaddy

  • Hero Member
  • *****
  • Posts: 12195
Re: Memo Question
« Reply #3 on: October 01, 2022, 07:00:17 pm »
Yes, or OnKeyUp, which is safer...
« Last Edit: October 01, 2022, 07:02:02 pm by Thaddy »
Manuals, manuals, manuals first.
You have incompetence and sheer incompetence.

Arioch

  • Sr. Member
  • ****
  • Posts: 414
Re: Memo Question
« Reply #4 on: October 01, 2022, 07:04:23 pm »
Yes, or OnKeyUp, which is safer...

what if i r-click and do paste without hitting keyboard ?

paweld

  • Hero Member
  • *****
  • Posts: 522
Re: Memo Question
« Reply #5 on: October 01, 2022, 07:46:02 pm »
Events OnEnter and OnExit:
Code: Pascal  [Select][+][-]
  1. uses
  2.   sha1;
  3.  
  4. var
  5.   memosha: String = '';
  6.  
  7. procedure TForm1.Memo1Enter(Sender: TObject);
  8. begin
  9.   Label1.Caption := '';
  10.   Label1.Color := clBtnFace;
  11.   memosha := SHA1Print(SHA1String(Memo1.Lines.Text));
  12. end;
  13.  
  14. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  15. begin
  16.   Memo1Exit(Sender);
  17. end;
  18.  
  19. procedure TForm1.Memo1Exit(Sender: TObject);
  20. begin
  21.   if memosha <> SHA1Print(SHA1String(Memo1.Lines.Text)) then
  22.   begin
  23.     Label1.Caption := 'Text has been changed';
  24.     Label1.Color := clRed;
  25.     //or save changes here
  26.   end
  27.   else
  28.   begin
  29.     Label1.Caption := 'Text has NOT been changed';
  30.     Label1.Color := clLime;
  31.   end;
  32.   memosha := '';
  33. end;
  34.  
Best regards
paweld

JLWest

  • Hero Member
  • *****
  • Posts: 1213
Re: Memo Question
« Reply #6 on: October 01, 2022, 08:22:39 pm »
Thanks All:

I'll test each answer. 

Kinda of unhappy I didn't think of this and try a few thing out before posting.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Arioch

  • Sr. Member
  • ****
  • Posts: 414
Re: Memo Question
« Reply #7 on: October 01, 2022, 08:41:16 pm »
ahem...

so i have a form, and two memos on it, and i just keep pressing TAB key - cycling through the memos

all the memos would have OnEnter / OnKeyDown / OnKeyUp /  OnExit events

yet no text would be actually changed

come on...

paweld

  • Hero Member
  • *****
  • Posts: 522
Re: Memo Question
« Reply #8 on: October 01, 2022, 08:52:39 pm »
@Arioch: I don't know if you're referring to my post - I actually didn't give a description, but I posted sample code: after entering the memo, I calculate the hash of the current text, which is also calculated on exit and compared with the initial one. Based on this, it is checked whether a modification has occurred - this is resistant to undoing changes.
Best regards
paweld

Arioch

  • Sr. Member
  • ****
  • Posts: 414
Re: Memo Question
« Reply #9 on: October 01, 2022, 09:09:22 pm »
frankly, if i would use the same idea then i'd do it "in your face" way: i woud compare the text itself, rather than hash

we have a "vanilla text" anyway, before we overwrote it, so - just compare with it :-)

jamie

  • Hero Member
  • *****
  • Posts: 4913
Re: Memo Question
« Reply #10 on: October 01, 2022, 11:28:58 pm »
Memo1.Modified?

Didn't anyone notice Bart ?

The MODIFIED property was put in there just to determine if user made changes verses software changes..

Ensure you clear it at some point because it does retain the last setting.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018