问个问题请大家顺路进来看看 ( 积分: 100 )

  • 主题发起人 主题发起人 zgwxldw
  • 开始时间 开始时间
Z

zgwxldw

Unregistered / Unconfirmed
GUEST, unregistred user!
MDI窗口的数据库
program Project1;

uses
windows,
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit3 in 'Unit3.pas' {Form3},
Unit4 in 'Unit4.pas' {sj: TDataModule},
Unit2 in 'Unit2.pas' {Form2},
Unit5 in 'Unit5.pas' {Form5},
Unit6 in 'Unit6.pas' {Form6},
Unit7 in 'Unit7.pas' {Form7},
Unit8 in 'Unit8.pas' {Form8},
Unit9 in 'Unit9.pas' {Form9},
Unit10 in 'Unit10.pas' {Form10};

{$R *.res}

begin
Application.Initialize;
Form9:= TForm9.Create(Application);//显示LOGO
Form9.Show;
Form9.Update;
sleep(1000);
Form9.Gauge1.MaxValue:=5;
Form9.Gauge1.Progress:=1 ;
Form8:=TForm8.Create(Application); //登录窗体,
Form9.Gauge1.Progress:=Form9.Gauge1.Progress+1;
Application.Title := '112233';
Form9.Gauge1.Progress:=Form9.Gauge1.Progress+1;
Application.CreateForm(TForm1, Form1);//fsMDIForm
Form9.Gauge1.Progress:=Form9.Gauge1.Progress+1;
Application.CreateForm(Tsj, sj);
Form9.Gauge1.Progress:=Form9.Gauge1.Progress+1;
Form9.Hide;
Form9.Free;
Form8.ShowModal;
Application.Run;
end.
在FORM1 主窗体中加入数据库路径就出错!而加在procedure TForm1.FormShow(Sender: TObject);里就不出错???代码一样??请教大家了
procedure TForm1.FormCreate(Sender: TObject);
begin
sj.con1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'
+'Data Source='+'Database/db1.mdb'+';'
+'Persist Security Info=False;'
+'Jet OLEDB:Database Password="123456";';//出错!!!!

end;
 
MDI窗口的数据库
program Project1;

uses
windows,
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit3 in 'Unit3.pas' {Form3},
Unit4 in 'Unit4.pas' {sj: TDataModule},
Unit2 in 'Unit2.pas' {Form2},
Unit5 in 'Unit5.pas' {Form5},
Unit6 in 'Unit6.pas' {Form6},
Unit7 in 'Unit7.pas' {Form7},
Unit8 in 'Unit8.pas' {Form8},
Unit9 in 'Unit9.pas' {Form9},
Unit10 in 'Unit10.pas' {Form10};

{$R *.res}

begin
Application.Initialize;
Form9:= TForm9.Create(Application);//显示LOGO
Form9.Show;
Form9.Update;
sleep(1000);
Form9.Gauge1.MaxValue:=5;
Form9.Gauge1.Progress:=1 ;
Form8:=TForm8.Create(Application); //登录窗体,
Form9.Gauge1.Progress:=Form9.Gauge1.Progress+1;
Application.Title := '112233';
Form9.Gauge1.Progress:=Form9.Gauge1.Progress+1;
Application.CreateForm(TForm1, Form1);//fsMDIForm
Form9.Gauge1.Progress:=Form9.Gauge1.Progress+1;
Application.CreateForm(Tsj, sj);
Form9.Gauge1.Progress:=Form9.Gauge1.Progress+1;
Form9.Hide;
Form9.Free;
Form8.ShowModal;
Application.Run;
end.
在FORM1 主窗体中加入数据库路径就出错!而加在procedure TForm1.FormShow(Sender: TObject);里就不出错???代码一样??请教大家了
procedure TForm1.FormCreate(Sender: TObject);
begin
sj.con1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'
+'Data Source='+'Database/db1.mdb'+';'
+'Persist Security Info=False;'
+'Jet OLEDB:Database Password="123456";';//出错!!!!

end;
 
主要区别在于: 在procedure TForm1.FormShow 中Form1已经创建,在 TForm1.FormCreate中,Form1还没有创建
 
如果是你应该放哪里?程序启动就指定路径
 
与创建Form无关的函数放在procedure TForm1.FormShow中比较安全
 
Application.CreateForm(TForm1, Form1);//fsMDIForm
Form1创建时sj还没有创建呀

Form9.Gauge1.Progress:=Form9.Gauge1.Progress+1;
Application.CreateForm(Tsj, sj);

procedure TForm1.FormCreate(Sender: TObject);
begin
sj.con1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'
...
end;
 
多人接受答案了。
 
后退
顶部