delphi7编译错误:[Error] Unit1.pas(116): Undeclared identifier: 'opendialog1'
我想在formcreate时更改memoname和opendialog1的属性,但是无法编译部分源码:unitUnit1;interfaceusesWindows,Mes...
我想在formcreate时更改memoname和opendialog1的属性,但是无法编译
部分源码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons, MmSystem, ToolWin, ComCtrls, XPMan,
ImgList;
type
TForm1 = class(TForm)
Label1: TLabel;
Image1: TImage;
BitBtn1: TBitBtn;
Label2: TLabel;
Label3: TLabel;
ToolBarMain: TToolBar;
ImageListTools: TImageList;
XPManifest1: TXPManifest;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
Panel1: TPanel;
Label4: TLabel;
MemoName: TMemo;
ToolBarEdit: TToolBar;
Shape1: TShape;
OpenDialog1: TOpenDialog;
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
{procedure FormCreate(Sender: TObject); }
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
cl: string;
lastfile,fi:text;
total,ra,flagtot:longint;
flagname:array[1..3000]of boolean;
checkflag:boolean;
implementation
{$R *.dfm}
…………
procedure loadfile;
var
nameoffile:string;
begin
assign(lastfile,'setting.ini');
reset(lastfile);
read(lastfile,nameoffile);
opendialog1.FileName :=nameoffile; //错误行Undeclared identifier: 'opendialog1'
fillchar(flagname,sizeof(flagname),true);
Memoname.lines.loadfromfile(nameoffile); //错误行
total:=memoname.lines.count;
while memoname.lines.strings[total]='' do dec(total);
checkflag := false;
close(lastfile);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
loadfile;
end;
end. 展开
部分源码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons, MmSystem, ToolWin, ComCtrls, XPMan,
ImgList;
type
TForm1 = class(TForm)
Label1: TLabel;
Image1: TImage;
BitBtn1: TBitBtn;
Label2: TLabel;
Label3: TLabel;
ToolBarMain: TToolBar;
ImageListTools: TImageList;
XPManifest1: TXPManifest;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
Panel1: TPanel;
Label4: TLabel;
MemoName: TMemo;
ToolBarEdit: TToolBar;
Shape1: TShape;
OpenDialog1: TOpenDialog;
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
{procedure FormCreate(Sender: TObject); }
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
cl: string;
lastfile,fi:text;
total,ra,flagtot:longint;
flagname:array[1..3000]of boolean;
checkflag:boolean;
implementation
{$R *.dfm}
…………
procedure loadfile;
var
nameoffile:string;
begin
assign(lastfile,'setting.ini');
reset(lastfile);
read(lastfile,nameoffile);
opendialog1.FileName :=nameoffile; //错误行Undeclared identifier: 'opendialog1'
fillchar(flagname,sizeof(flagname),true);
Memoname.lines.loadfromfile(nameoffile); //错误行
total:=memoname.lines.count;
while memoname.lines.strings[total]='' do dec(total);
checkflag := false;
close(lastfile);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
loadfile;
end;
end. 展开
2个回答
展开全部
出错的原因:丛郑迅您所定义的loadfile过程不属于类TForm1,而OpenDialog1属于类TForm1,在类以外的过程引用类(这里的容器是TForm1)的控件,必须在控件前指定控丛唯件所属的类(这里的容器是TForm1),则:
两种解决办法:
(1)//procedure loadfile ==> procedure TForm1.loadfile
type ...OpenDialog1: TOpenDialog;
procedure BitBtn1Click(Sender: TObject);
// (添加代码) ==>
procedure loadfile;
//OK !~
(2)opendialog1.FileName :=nameoffile; ==> Form1.opendialog1.FileName :=nameoffile
回答完渗此毕,送分!
两种解决办法:
(1)//procedure loadfile ==> procedure TForm1.loadfile
type ...OpenDialog1: TOpenDialog;
procedure BitBtn1Click(Sender: TObject);
// (添加代码) ==>
procedure loadfile;
//OK !~
(2)opendialog1.FileName :=nameoffile; ==> Form1.opendialog1.FileName :=nameoffile
回答完渗此毕,送分!
参考资料: 原创
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private
{ Private declarations }
这里碰前加上
Porcedure LoadFile;
-----------------------------------------------------------------------------------------------
procedure loadfile; //这里改成Procedure TForm1.LoadFile;
var
nameoffile:string;
begin
assign(lastfile,'setting.ini');
reset(lastfile);
read(lastfile,nameoffile);
opendialog1.FileName :=nameoffile; /饥吵物/错误行Undeclared identifier: 'opendialog1'
fillchar(flagname,sizeof(flagname),true);
Memoname.lines.loadfromfile(nameoffile); //错误行
total:=memoname.lines.count;
while memoname.lines.strings[total]=''烂液 do dec(total);
checkflag := false;
close(lastfile);
end;
{ Private declarations }
这里碰前加上
Porcedure LoadFile;
-----------------------------------------------------------------------------------------------
procedure loadfile; //这里改成Procedure TForm1.LoadFile;
var
nameoffile:string;
begin
assign(lastfile,'setting.ini');
reset(lastfile);
read(lastfile,nameoffile);
opendialog1.FileName :=nameoffile; /饥吵物/错误行Undeclared identifier: 'opendialog1'
fillchar(flagname,sizeof(flagname),true);
Memoname.lines.loadfromfile(nameoffile); //错误行
total:=memoname.lines.count;
while memoname.lines.strings[total]=''烂液 do dec(total);
checkflag := false;
close(lastfile);
end;
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询