Saturday, August 5, 2017

Error: Cannot Restore Form State--No TRzRegIniFile Component Specified

It's been a while since I fired up Delphi, about three months. And you know, it's true what they say "If you don't use it you loose it". I love my Raize Components now called Konopka VCL Controls, they make a lot of things very easy. For example, automatically remembering the size and position of form windows. I've used this dozens of times. It's a no-brainer.

So today, I was playing around with the DBGrid, trying different things. I created a new project with a Form and a Data Module. Added a lookup field to the grid. Just having fun and experimenting with stuff. One of the things I wanted to do but haven't got around to yet, was save the column widths of the grid after they've been resized. I find it annoying always having to resize the columns every time a program runs. That will be for another day.

Anyway, I decided I wanted to start by saving the state of the Main form window, just like I've done in the past. Drop a RzRegIniFile component on the Data Module. Drop an RzFormState component on the Main form. Set the RzFormState.RegIniFile property to the DM.RzRegIniFile component. And Voila... Done! Right!

NOT!

I kept getting the following error: "Cannot Restore Form State--No TRzRegIniFile Component Specified".



I'm going back and forth like a madman, checking things on the Data Module and the Main form. I tried dropping and re-adding the components. Nope. I started googling the error... nothing. Then it hits me. It's got to be a timing thing.

Yup! I opened the source file for the project and sure as shit, the Data Module was being created after the Main form.
begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm4, Form4);
  Application.CreateForm(TDataModule5, DataModule5);
  Application.Run;
end.
I moved the creation of the Data Model before the Main form and bingo... works like a champ!
begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TDataModule5, DataModule5);
  Application.CreateForm(TForm4, Form4);
  Application.Run;
end.
I'm amazed how quickly I lost sight of this little detail. I was only away from Delphi for maybe three months. Gee Whiz.

Enjoy!

Semper Fi,
Gunny Mike

No comments:

Post a Comment