rowanphilip
rowanphilip

Reputation: 319

My application disappears from the task bar as soon as I move away from the main form

Below is my code for the clicking of a button on the main form.

procedure TfrmLoginSelect.btnStudentLoginClick(Sender: TObject);
var
  FilePAthFile:TextFile;
begin
  assignFile(filepathfile,FilePathLocation);
  reset(filepathfile);
  readln(filepathfile,FilePath);
  closeFile(filepathfile);
  frmLoginSelect.visible:=False;
  frmStudentLogin.visible:=True;
end;

Whenever this is clicked, however, the Delphi application is removed from the task bar. What am I doing wrong and how do I prevent this?

Upvotes: 0

Views: 473

Answers (1)

David Heffernan
David Heffernan

Reputation: 613572

The problem is here:

frmLoginSelect.Visible := False;

The frmLoginSelect form is the main form. That is defined to be the first form created by a call to Application.CreateForm. The main form is the form associated with the taskbar button. Taskbar buttons only show when their associated window is visible. By hiding the main form you are also hiding the taskbar button.

It's difficult to give advice on how to resolve this. We cannot see enough of your program to say for sure what the right solution is. It's likely that you don't want frmLoginSelect to be the main form. But I cannot tell which form should be the main form.

It looks like you have a series of login forms that have to be navigated before the real main form can be used. I would handle that by showing the main form at startup, but then show the login forms as modal dialogs. Only if the user succeeds in navigating through the login forms does the main form become usable. Of course, I'm speculating wildly on what your application is really doing.

My broad advice in this area is to call Application.CreateForm once and once only during the lifetime of your program. For all other form creation call the form's constructor. Remove global form variables. All this goes against what the IDE wants you to do. But the IDE was designed when Borland were luring VB devs to Delphi. Don't let that drive your code architecture.

Upvotes: 4

Related Questions