Forum > RichMemo

RichMemo - OnChange event is fired - why and when?

(1/1)

Nicole:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Saved_dasRichMemo:= true; // Aufruf muss vorher und nachher stehen, weil "Laden" eine Änderung ist  ToolButton_oeffneClick(RichEdit_WICHTIGDatei); // öffnet die Datei wie alle anderen Dateien)  Saved_dasRichMemo:= true; // das geladene IST schon gespeichert   
 
loading routine file into richMemo

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  // öffnet eine übergebene Datei für RichMemo default in rtf-Format oder startet den open-Dialogprocedure TForm_Notizen.ToolButton_oeffneClick(Datei: string); begin   if not Saved_dasRichMemo then  // wenn eine ungesicherte Datei vorhanden ist, wird specher abgefragt      case Application.MessageBox('Änderungen speichern?',                                'Achtung',MB_YESNOCANCEL)        of IDYES    : Speichern;  // ungespeicherte Änderungen sichern           IDCANCEL : exit;        end;   if datei <> '' then begin    // wir ein Dateiname via Code übergeben, wo wird diese Datei geöffnet     RichMemo_wichtig.Lines.LoadFromFile(datei);     RichMemoName:=datei; // die Datei ist der Name und ihr Pfad     IstGespeichert(self); // wenn wir eine Datei neu öffnen, ist die Datei gespeichert     exit;   // die Funktion oben setzt die Kopfzeile und aktiviert / deaktiviert die Icons  end;   // wird kein Dateiname übergeben, so öffnet sich der Dialog  OpenDialog_RichMemoNotizen.InitialDir:=Pfad + '\Texte'; // dort werden rtf Dateien primär gesucht  if OpenDialog_RichMemoNotizen.Execute then begin    datei := AnsiUpperCaseFileName(OpenDialog_RichMemoNotizen.Filename);    datei := AnsiStrRScan(PChar(datei),'.');    RichMemo_wichtig.Lines.LoadFromFile(OpenDialog_RichMemoNotizen.Filename);    RichMemo_wichtig.Modified := False;    RichMemoName:= OpenDialog_RichMemoNotizen.Filename; // diese Var hält den Pfad der Datei im Arbeitsspeicher    Caption := RichMemoName;    end;            
   
indirect setting of "not saved", which includes the icons for saving as well


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// RichMemo stellt fest, ob die Datei/ der Text bereits gesichert ist.procedure TForm_Notizen.IstVeraendert(Sender: TObject);begin// showMessage('Change wurde ausgelöst. gesichert wird false');  Saved_dasRichMemo:=False;  ToolButton_speichern.Enabled:=true; // zeigt im Interface an, dass gesichert ist  Form_Notizen.Caption:='ungesichert ' + RichMemoName;end;
   
end;   


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

Nicole:
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:
What happens is that the modified property is set. If you do not want that set the modified property manually to false.

Nicole:
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.

Navigation

[0] Message Index

Go to full version