Recent

Author Topic: RichMemo - OnChange event is fired - why and when?  (Read 2325 times)

Nicole

  • Hero Member
  • *****
  • Posts: 1009
RichMemo - OnChange event is fired - why and when?
« on: June 24, 2023, 05:37:01 pm »
In my OnCreateForm1 I have some lines, which load a file into a RichMemo.
A Var by the name of "Saved_dasRichMemo" shall hold the status, if the RichMemo is saved or not.
Code: Pascal  [Select][+][-]
  1. Saved_dasRichMemo = true
means "saved" which I use to speak more clearly below.

This does not work for me: The status says "unsaved", although it is "saved".
At the end of the OnCreate event the status is "saved".
When the form shows up, the variable window shows me an "invalid" for this var
When I click at the open-new-file-Icon the value is "unsaved".
I am talking about line 5 of the third code-block   " if not Saved_dasRichMemo... "

I am puzzled by this. I ran a search for this var, but could not find any suspect use or local declaration or so.
Does there happen anything between the onCreateOfForm and the visual showing-up of a RichMemo?


here are some details
some lines of the create event

Code: Pascal  [Select][+][-]
  1. Saved_dasRichMemo:= true; // Aufruf muss vorher und nachher stehen, weil "Laden" eine Änderung ist
  2.   ToolButton_oeffneClick(RichEdit_WICHTIGDatei); // öffnet die Datei wie alle anderen Dateien)
  3.   Saved_dasRichMemo:= true; // das geladene IST schon gespeichert  
 
 
loading routine file into richMemo
Code: Pascal  [Select][+][-]
  1.   // öffnet eine übergebene Datei für RichMemo default in rtf-Format oder startet den open-Dialog
  2. procedure TForm_Notizen.ToolButton_oeffneClick(Datei: string);
  3.  
  4. begin
  5.    if not Saved_dasRichMemo then  // wenn eine ungesicherte Datei vorhanden ist, wird specher abgefragt
  6.       case Application.MessageBox('Änderungen speichern?',
  7.                                 'Achtung',MB_YESNOCANCEL)
  8.         of IDYES    : Speichern;  // ungespeicherte Änderungen sichern
  9.            IDCANCEL : exit;
  10.         end;
  11.  
  12.   if datei <> '' then begin    // wir ein Dateiname via Code übergeben, wo wird diese Datei geöffnet
  13.      RichMemo_wichtig.Lines.LoadFromFile(datei);
  14.      RichMemoName:=datei; // die Datei ist der Name und ihr Pfad
  15.      IstGespeichert(self); // wenn wir eine Datei neu öffnen, ist die Datei gespeichert
  16.      exit;   // die Funktion oben setzt die Kopfzeile und aktiviert / deaktiviert die Icons
  17.   end;
  18.  
  19.   // wird kein Dateiname übergeben, so öffnet sich der Dialog
  20.   OpenDialog_RichMemoNotizen.InitialDir:=Pfad + '\Texte'; // dort werden rtf Dateien primär gesucht
  21.   if OpenDialog_RichMemoNotizen.Execute then begin
  22.     datei := AnsiUpperCaseFileName(OpenDialog_RichMemoNotizen.Filename);
  23.     datei := AnsiStrRScan(PChar(datei),'.');
  24.     RichMemo_wichtig.Lines.LoadFromFile(OpenDialog_RichMemoNotizen.Filename);
  25.     RichMemo_wichtig.Modified := False;
  26.     RichMemoName:= OpenDialog_RichMemoNotizen.Filename; // diese Var hält den Pfad der Datei im Arbeitsspeicher
  27.     Caption := RichMemoName;
  28.     end;
  29.        
  30.  
   
   
indirect setting of "not saved", which includes the icons for saving as well

Code: Pascal  [Select][+][-]
  1. // RichMemo stellt fest, ob die Datei/ der Text bereits gesichert ist.
  2. procedure TForm_Notizen.IstVeraendert(Sender: TObject);
  3. begin
  4. // showMessage('Change wurde ausgelöst. gesichert wird false');
  5.   Saved_dasRichMemo:=False;
  6.   ToolButton_speichern.Enabled:=true; // zeigt im Interface an, dass gesichert ist
  7.   Form_Notizen.Caption:='ungesichert ' + RichMemoName;
  8. end;

   
end;   


Triggered is the thing, by the Change-Event of the RichMemo, see screenshot and calling stack.

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: RichMemo - OnChange event is fired - why and when?
« Reply #1 on: June 27, 2023, 10:24:13 am »
No answer up to now. This project is a small one and I cared not to use any databases, but only textfiles.
So I can upload it as whole.
I hope, it will run in your environment (shall work with Win 7 and Win 10)

It is about the fourth Tabsheet and there the RichMemo_wichtig, focus the second icon there "öffnen" = open.

Please set these breakpoints in line: 431, 1343 and 1900 of the Unit_Notizen

So what it does:
create event is line 431
Saved_dasRichMemo:= true;
just to see "yes, is set"
The Var is for knowing, if the RichMemo has changed or not.

set a second breakpoint into the onChance-Event to line 1900,
which makes set this Saved_dasRichMemo to false.
On start up you see it fired, because the default file is loaded.
After loading the Var Saved_dasRichMemo is set to "true" again.
So IT SHALL be true.

The form shows up.
click the second icon "open" with the glass-image
see breakpoint to line 1343 now
==> the value Saved_dasRichMem is false now
Why??!!

Cleanup of the project:
Go to your "own files" and delete the directory "TermineAb_2022".
Is is generated by the create-event and holds all files needed including the ini.
Nothing else is written to your computer.



Thaddy

  • Hero Member
  • *****
  • Posts: 16360
  • Censorship about opinions does not belong here.
Re: RichMemo - OnChange event is fired - why and when?
« Reply #2 on: June 27, 2023, 11:10:52 am »
What happens is that the modified property is set. If you do not want that set the modified property manually to false.
There is nothing wrong with being blunt. At a minimum it is also honest.

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: RichMemo - OnChange event is fired - why and when?
« Reply #3 on: June 27, 2023, 05:30:12 pm »
Thank you for the reply.

What exactly do you mean by "set the property to false"?
Where and how?
There is no problem to set it to false on startup once, although I am not sure in which line best.

However this function shall give a warning, in case the user modifies a RichMemo and would be going to lose this modification by any action (open anything else, close the software...).
So generally I WANT the onChange event to work. But only if there is a modification.
At the moment it works "everytime". At least it feels for me like this.

 

TinyPortal © 2005-2018