0

I'm using the LoadComponentFromFile and SaveComponentToFile posted here: How to save and restore a form?

The routines are working fine. However, after saving and loading the form I can not change any of the form's component's values. For example, I have the following:

  MainForm.LoadComponentFromFile(CustomPrintDialog, FileName+'CustomPrintDialog.txt');
  NewFinalDepth := CurrentChild.GetMaxDepth;
  CustomPrintDialog.ToEditBox.Value := round(NewFinalDepth);

The ToEditBox.Value is not changed by the line where it is assigned NewFinalDepth. Is there a setting somewhere in the LoadComponent that is preventing the updating of ToEditBox.Value?

ToEditBox.EditorEnabled and Enabled are both True.

This is the CustomPrintDialog OkButtonClick and ToEditBoxChange routines.

procedure TCustomPrintDialog.OKBtnClick(Sender: TObject);
var
  Filename : string;
begin
  Filename := MainForm.GetCurrentFileName;
  FileName := Copy(Filename, 0, LastDelimiter('.',Filename) - 1);
  FileName := FileName + 'CustomPrintDialog.txt';
  MainForm.SaveComponentToFile(CustomPrintDialog, FileName);
end;

The SaveComponentToFile restores the original values to CustomPrintDialog. Why?

procedure TCustomPrintDialog.ToEditBoxChange(Sender: TObject);
var
  Inches, Value : integer;
begin
  if  not(TryStrToInt(ToEditBox.Text, Value)) then
    exit;
  try
    if FromEditBox.Value < ToEditBox.Value then
      begin
        if PrintCoverSheetCheckBox.Checked then
          Inches := LONGHEADINGLENGTH
        else if PrintheadingCheckBox.Checked then
          Inches := MEDIUMHEADINGLENGTH
        else
          Inches := NOHEADINGLENGTH;
        SetInchesRequired(Inches);  // Inches is paper length required to print document
      end;
  except
    on EConvertError do
      begin
      end;
  end;
end;
Community
  • 1
  • 1
user1429254
  • 327
  • 1
  • 3
  • 10
  • 1
    How do you test for `ToEditBox.Value` to be changed? Are you aware that during `LoadComponentFromFile` all child components of `CustomPrintDialog` are freed and recreated while loading? Perhaps the `ToEditBox` that is changed is not the same as the one you are looking at? – Uwe Raabe Jun 09 '15 at 21:38
  • How do I find the new one? Wouldn't CustomPrintDialog.ToEditBox refer to the new component and not the old one? The application is a real-time application that uses to and from to print a document using to and from as the values to print. After loading the printer dialog the next line is supposed to update the to value so that when printing the file the from and to values are updated appropriately. – user1429254 Jun 09 '15 at 23:01
  • 1
    I can't tell without knowing more about CustomPrintDialog. Can you add the source? – Uwe Raabe Jun 10 '15 at 06:48

0 Answers0