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