Rac Devw
Rac Devw

Reputation: 21

show window before terminate

I have a delphi application that, on startup, checks to see if a process is already running, if it is running, I pass data over to that process and terminate the current process. The problem: In terminating the current process, the window of the app flashes for a split second prior to termination. All the code is in the application initialization, before that main form is even created, so I don't understand how it could show the form for a split second. I have tried numerous things like making the window invisible, nothing seems to work. Is there something I am doing wrong.

Upvotes: 1

Views: 200

Answers (1)

Andreas Rejbrand
Andreas Rejbrand

Reputation: 108948

You are apparently not terminating soon enough. I'd do something like

program Project1;

uses
  Forms,
  Windows,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

function PrevInstance: boolean;
begin
  ...
end;

procedure PassData;
begin
  ...
end;

begin

  if PrevInstance then
  begin
    PassData;
    Exit;
  end;


  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Update: I believe you do something like

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure MyInitProc;
begin
  if true then Application.Terminate;
end;

initialization
  InitProc := @MyInitProc;

end.

This will not work, because Application.Terminate doesn't terminate the application immediately. Instead, it simply posts a WM_QUIT message. This message will be received and acted upon after all initialisation is completed.

Upvotes: 2

Related Questions