unit test10;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
Shape5: TShape;
Shape6: TShape;
Shape7: TShape;
Shape8: TShape;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
i:integer ;
b:string;
c:tcomponent;
procedure TForm1.FormCreate(Sender: TObject);
begin
b:='shape';
i:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
i:=i+1;
label1.Caption := b + inttostr(i);
c := Components[i];
tComponent(Components[i]).visible := true;
end;
end.出错信息如下:[Error] test10.pas(43): Undeclared identifier: 'visible'请问我如何用表量替代控件名称?
谢谢!
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
Shape5: TShape;
Shape6: TShape;
Shape7: TShape;
Shape8: TShape;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
i:integer ;
b:string;
c:tcomponent;
procedure TForm1.FormCreate(Sender: TObject);
begin
b:='shape';
i:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
i:=i+1;
label1.Caption := b + inttostr(i);
c := Components[i];
tComponent(Components[i]).visible := true;
end;
end.出错信息如下:[Error] test10.pas(43): Undeclared identifier: 'visible'请问我如何用表量替代控件名称?
谢谢!
TShape(FindComponent('Shape'+IntToStr(i))).Visible := True ;
其实只要改一句就行了.
Tshape(Components[i]).visible := true;佩服计算机质子, 我想了一下午的问题你一会儿就出来答案了.