程序描述:
    form1为一个登录界面,当checkbox1.checked 选中时,输入密码正确就可以进入form7;checkbox1未选中时,输入密码正确进入form6。
问题描述:
    总是出现“violation at address 0046f692 in module 'roject1.ext'.read of address 000002f4'”提示,我也找不出代码那里有问题,用step能看到出现问题的地方为下面星号标注处。
还有一个问题,
    Application.Initialize;是什么作用,和vb中的一样么,我看到一些文章说,vb中的相当于delphi中的create,那delphi中的Application.Initialize;是做什么用的,谢谢大家。(分不够我可以另加)    
project1 代码
program Project1;{%File 'Project1.~dpr'}
{%File 'Project1.cfg'}
{%File 'Project1.dof'}
{%File 'Project1.exe'}uses
  Forms,
  Unit100 in 'Unit100.pas' {Form1},
  Unit101 in 'Unit101.pas' {QueryDS: TDataModule},
  Unit102 in 'Unit102.pas' {Form2},
  Unit103 in 'Unit103.pas' {Form3},
  Unit104 in 'Unit104.pas' {Form4},
  Unit105 in 'Unit105.pas' {Form5},
  Unit106 in 'Unit106.pas' {Form6},
  Unit107 in 'Unit107.pas' {Form7},
  Unit108 in 'Unit108.pas' {Form8},
  Unit109 in 'Unit109.pas' {Form9},
  Unit1100 in 'Unit1100.pas' {Form10};{$R *.res}begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  if form1.CheckBox1.Checked=False then
  begin
  Application.CreateForm(TForm7,Form7);
  Application.CreateForm(TQueryDS,QueryDS);
  Application.CreateForm(TForm4,Form4);
  Application.CreateForm(TForm5,Form5);
  Application.Run;
  end
  else
  begin
  Application.CreateForm(TForm6,Form6);
  Application.CreateForm(TForm2,Form2);
  Application.CreateForm(TForm3,Form3);
  Application.CreateForm(TQueryDS,QueryDS);
  Application.CreateForm(TForm8,Form8);
  Application.CreateForm(TForm9,Form9);
  Application.CreateForm(TForm10,Form10);
  Application.Run;
  end;end.
form1代码unit Unit100;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    Panel1: TPanel;
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  Times:Integer=0;implementation{$R *.dfm}
uses unit106,unit107;
procedure TForm1.Button1Click(Sender: TObject); var
 pwdFile:textfile;
 pwdStr:string;
begin if CheckBox1.Checked=true then assignfile(pwdFile,'E:\typer\dephi程序员\图书馆管理系统\data\管理员.txt')
 else assignfile(pwdFile,'E:\typer\dephi程序员\图书馆管理系统\data\学生.txt');
 reset(pwdFile);
 readln(pwdFile,pwdStr);
 closefile(pwdFile);
 Times:=Times+1;
 if Edit1.Text=pwdStr then
  begin
   if CheckBox1.Checked=true then Form6.Show
   else Form7.Show;
  end
 else
  begin
  if MessageDlg('密码输入错误,是否退出?',mtConfirmation,[mbYes,mbNo],0)=mrYes then close
  else if Times<3 then edit1.SetFocus
  else
   begin
    MessageDlg('密码严重错误,退出。',mtInformation,[mbOk],0);
    Application.Terminate;
  end;
 end;
end;end.

解决方案 »

  1.   

    如果这样写TForm1.Button1Click,你的form6或者form7肯定是有一个没有创建,这样当你默认是没有选中时,当然form6在程序中还没有创建,你运行选中,点击按钮后,form6.show就是错误的了。因为他还没有创建呢!!我想你简单改成这个样子肯定不会出问题了:
    begin
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
        Application.CreateForm(TForm7,Form7);
      Application.CreateForm(TQueryDS,QueryDS);
      Application.CreateForm(TForm4,Form4);
      Application.CreateForm(TForm5,Form5);
      Application.CreateForm(TForm6,Form6);
      Application.CreateForm(TForm2,Form2);
      Application.CreateForm(TForm3,Form3);
      Application.CreateForm(TForm8,Form8);
      Application.CreateForm(TForm9,Form9);
      Application.CreateForm(TForm10,Form10);
      Application.Run;
      
    end.
      

  2.   

    代碼錯誤: 
     Application.CreateForm(TForm10,Form10);
      Application.Run;
      end;
    修改成如下:
      Application.CreateForm(TForm10,Form10);
      end;
      Application.Run;
      

  3.   

    我說的還不對!應該是: if Edit1.Text=pwdStr then
      begin
       if CheckBox1.Checked=true then Form6.Show
       else Form7.Show;
      end
    這裹出問題, 窗體還沒創建就 show!!!
      

  4.   

    CheckBox1.Checked=true /false
    只有一个情况,所以只有一个form6,or fmor7能创建,你显示的时候没创建就出错了开始的时候全部创建算了,管他干嘛
    Application.Initialize;
    系统初始化,由系统控制,不用理他
      

  5.   

    caohonglong2000(chl) 谢谢,你那种方法一定能实现的,你等着分吧,不会少给你的。
     在project代码中一定要把这些窗体都包括到里面么。
     如果我的project代码中还是用到选择语句,能不能实现。
     有没有哪位知道Application.Initialize的作用。