Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

Show a PasswordDlg

I want a PasswordDlg appears immediately after form1 created.
Where I should put the statement, PasswordDlg.ShowModal?
I don't want to put it in a button Onclick event, I want that is automatically done.
I don't want to put it in the Onpaint event of form1, since whenever the form repainted PasswordDog would appear again.
0
zhuhail
Asked:
zhuhail
  • 2
1 Solution
 
sleachCommented:
If you want the Pass Dialog shown before the form is displayed, place it in the OnCreate event of the form.

If you want the Pass Dialog shown after the form is displayed, but before the user can do anything, place it in the OnActivate method, and set a global flag so that it is only displayed the first time the event occurs.

0
 
zhuhailAuthor Commented:
Thank you.

I have tried to put PasswordDlg.ShowMadal in OnActive event of Form1. That worked fine. However, when put that in OnCreate event of Form1, I got an error message:
'Access violation at address 0041DC8F. Read of address FFFFFFFF'
What is the message means?
0
 
sleachCommented:
PasswordDlg must be a delphi form.  I used a MessageBox to test.  The problem is that PasswordDlg is not the first form created.  Your main form is.  Therefore your trying to ShowModal a form that has not yet been created.

The solution is to create the PasswordDlg form at runtime.
REMOVE PasswordDlg from the projects AutoCreate list with the project manager.  Then Create the form at runtime.  An example of how to do this is below.

procedure TForm1.FormCreate(Sender: TObject);
var
PasswordDlg:  TPasswordDlg;
begin
PasswordDlg := TPasswordDlg.create(self);
PasswordDlg.ShowModal;
end;

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now