Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Dec : Creating a new instance of a form
| Subject: | Creating a new instance of a form |
| Posted by: | "Mark Smith" (marksmi..@jungle-monkey.com) |
| Date: | Wed, 26 Dec 2007 23:47:37 |
Hi,
I am trying to create a new form as below.
The problem is when it gets to frmMain.Create(Application); the
following error occurs:
"Access violation at address 0046D929 in module 'Client.exe'. Read of
address 00000000."
What am I doing wrong? And is there a more elegant way of doing it? I
need the new form to be independent so that it exists even after the
original form is destroyed.
Thanks,
unit Login;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Dialogs, StdCtrls,Forms, Main;
type
TfrmLogin = class(TForm)
Label1: TLabel;
Label2: TLabel;
txtComputer: TEdit;
txtPassword: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmLogin: TfrmLogin;
frmMain: Tfrmmain;
implementation
{$R *.dfm}
procedure TfrmLogin.Button1Click(Sender: TObject);
begin
frmMain.Create(Application);
frmMain.Visible := true;
frmMain.Caption := 'Connected to: ' + txtComputer.Text;
Destroy;
end;
procedure TfrmLogin.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;
end.