不太清楚为什么, 可能是你创建的控件所要的文件没有包含,一般在设计时,拉一个你要创建的控件,再删除就行了。 动态创建控件就这样: var Btn:TButton; begin Btn:=TButton.Create(Self); Btn.Parent:=Self; Btn.Left:=30; Btn.Top:=20; end;
说具体点,不然不知道你错在哪里 1、动态创建的控件要指定parent 2、要释放
就是uses部分没有写上所要的单元名称
有craate,parent,再有位置,然后其他的一些属性就可以了
[Pascal Error] Unit1.pas(1): Unable to invoke Code Completion due to errors in source code [Error] Unit1.pas(20): Undeclared identifier: 'TProgressar'
[Pascal Error] Unit1.pas(1): Unable to invoke Code Completion due to errors in source code [Error] Unit1.pas(20): Undeclared identifier: 'TProgressar' 你的错误肯定不是动态创建的问题!动态创建只要你的控件定义对了,再USE你该控件必须的UNIT, 想怎么创建都可以! uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs,ADODB, DB; //要用到AODQUERY就要USE ADOD; var adoqmodify:tadoquery; begin try adoqmodify:=tadoquery.Create(nil); adoqmodify.Connection:=form1.ADOConnection1; adoqmodify.SQL.Text:='select * from table'; adoqmodify.Open; finally adoqmodify.Free; end; end;//OK!…… end;
你吧TProgressar的单元文件找出来加上
finally XXX.free; end;
uses necesaryunit; //////////////// if you do not know which unit to use,open "delphi help" and type the class you are using for instance "TProgressbar",then you will know everything.
var progressbar:TProgressBar; begin progressbar:=TProgressBar.Create(self); with progressbar do begin parent:=self; align:=alBottom; end; end; 别人告我这么写,告完就消失了!!!!!!!!!!!
progressbar 的单元文件是QComCtrls
以下的东西我试了,在我这里可以。(别忘了加上单元QComCtrls) 假设使用一个button来创建控件。 现在窗体上放一个progressbar控件,这样会自动声明progressbar1:TProgressBar; 然后在 TForm1.Button1Click里写上 var progressbar1:TProgressBar; begin progressbar1:=TProgressBar.Create(self); with progressbar1 do begin progressbar1.parent:=self; progressbar1.align:=alBottom; end; end; 然后将刚才自己放上的那个progressbar删除。编译一下试试,应当就可以了,如果不行,权当灌水了:)
动态创建控件就这样:
var
Btn:TButton;
begin
Btn:=TButton.Create(Self);
Btn.Parent:=Self;
Btn.Left:=30;
Btn.Top:=20;
end;
1、动态创建的控件要指定parent
2、要释放
[Error] Unit1.pas(20): Undeclared identifier: 'TProgressar'
[Error] Unit1.pas(20): Undeclared identifier: 'TProgressar'
你的错误肯定不是动态创建的问题!动态创建只要你的控件定义对了,再USE你该控件必须的UNIT,
想怎么创建都可以!
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs,ADODB, DB;
//要用到AODQUERY就要USE ADOD;
var
adoqmodify:tadoquery;
begin
try
adoqmodify:=tadoquery.Create(nil);
adoqmodify.Connection:=form1.ADOConnection1;
adoqmodify.SQL.Text:='select * from table';
adoqmodify.Open;
finally
adoqmodify.Free;
end;
end;//OK!……
end;
XXX.free;
end;
necesaryunit;
////////////////
if you do not know which unit to use,open "delphi help" and type the class you are using for instance "TProgressbar",then you will know everything.
例如创建ADO对象时注意,没有FORM的工程,如服务,不能直接创建ADO,否则出错,需要初始化COM组件
解决方法是:查查TProgressar在哪个单元下,然后添加。简单的方法是添加一个该控件后删除!
progressbar:TProgressBar;
begin
progressbar:=TProgressBar.Create(self);
with progressbar do
begin
parent:=self;
align:=alBottom;
end;
end;
别人告我这么写,告完就消失了!!!!!!!!!!!
假设使用一个button来创建控件。
现在窗体上放一个progressbar控件,这样会自动声明progressbar1:TProgressBar;
然后在 TForm1.Button1Click里写上
var
progressbar1:TProgressBar;
begin
progressbar1:=TProgressBar.Create(self);
with progressbar1 do
begin
progressbar1.parent:=self;
progressbar1.align:=alBottom;
end;
end;
然后将刚才自己放上的那个progressbar删除。编译一下试试,应当就可以了,如果不行,权当灌水了:)