Title: Message
Bob
 
If you hack the main program pas file you can get no forms autocreated
(It is ideal to have something autocreated such as a Datamodule or the IDE gets bent)
 
ie  My main programs all look like
 
begin
  {Attempt to create a named mutex}
  CreateMutex(nil, false, PChar(AppCentral.AppName));
  {if it failed then there is another instance}
  if GetLastError = ERROR_ALREADY_EXISTS then begin
   {Send all windows our custom message - only our other}
   {instance will recognise it, and restore itself}
    SendMessage(HWND_BROADCAST, RegisterWindowMessage(PChar(AppCentral.AppName)), 0, 0);
    Halt(0);
  end;
  Application.Initialize;
  Application.CreateForm(TISMainDataModule, ISMainDataModule);
  SplashForm := TSplashForm.Create(nil);
  with SplashForm do
  try
    if not AppCentral.Developing then
    begin
      Show;   // show a splash screen
      Update; // force display
    end;
    try
  AppCentral.AllOk := ISMainDataModule.Initialise(SplashForm.Panel1);
      if AppCentral.AllOK then Application.CreateForm(TISMainForm, ISMainForm);
      if not AppCentral.AllOk then Abort;
      AppCentral.TitleApplication(ISMainForm);
      AppCentral.CheckOk;
      AppCentral.HideSplash := true;
      SplashForm.Release;
      if AppCentral.AllOK then ISMainForm.Show;
    except
      Application.Terminate;
    end;
  finally
    SplashForm.Release;
  end;
  Application.Run;
end.
 
in which case thew IDE says that ISMainDataModule is the main form! and ignores the rest
 
HTH
 
Neven
 
 
----- Original Message -----
From: Bob Osborn
Sent: Wednesday, October 02, 2002 2:08 PM
Subject: [DUG]: Persistent Main form

Hi All
 
I'm having trouble trying to instantiate the main form for an application by reading it from a resource file.  My objective is to have the form restore itself to the same settings as the previous session when it closed.
 
I don't have any problems restoring individual controls on the form by streaming them to and from a stream file using the OnCreate and OnClose events, but this seems an inconvenient way of doing it when I ought to be able to restore the form in one go.
 
I'm able to read and write sub-forms successfully using Read/WriteComponentResFile() and the CreateNew() class method,  but I can't do this with the main form because it is created by Application.CreateForm() which uses the resource file that is compiled into the .exe.  There doesn't seem to be any way of switching TApplication's MainForm to another form and so I can't see an easy workaround (or any workaround) -  but maybe someone else has devised a way to do it.
 
My apologies if this subject has been thrashed on the list before.
 
 
Bob Osborn
 

Reply via email to