1

Topic: Arrays of buttons

It is necessary that at creation of the form names of buttons changed on colors of a rainbow (not clear it is colors of a rainbow)

var
Form1: TForm1;
raduga:array [1. 7] of string = ('... ');
Button: Array [1. 7] of TButton;
implementation
{$R *.dfm}
procedure TForm1.FormCreate (Sender: TObject);
var i:integer;
begin
for i: = 1 to 7 do begin
Button [i].Caption: = raduga [i];
end;
end;

2

Re: Arrays of buttons

The program is launched but the function does not fulfill

3

Re: Arrays of buttons

I created 7 buttons. Or you about what?

4

Re: Arrays of buttons

temir123 wrote:

the program is launched but the function does not fulfill

Not subtly that does not work. Buttons need to be created (already told) and to place them on the form. I.e. your cycle becomes a little complicated...

5

Re: Arrays of buttons

temir123 wrote:

I created 7 buttons. Or you about what?

Show, where you created them.

6

Re: Arrays of buttons

type
TForm1 = class (TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
Shape5: TShape;
Shape6: TShape;
Shape7: TShape;
procedure FormCreate (Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end;
var
Form1: TForm1;
raduga:array [1. 7] of string = (' ', ' orange ', ' yellow ';
' green ', ' blue ', ' dark blue ', ' violet ');
Button: Array [1. 7] of TButton;
implementation
{$R *.dfm}
procedure TForm1.FormCreate (Sender: TObject);
var
i:integer;
begin
for i: = 1 to 7 do begin
Button [i].Caption: = raduga [i];
end;
end;
end.

7

Re: Arrays of buttons

shape there it is required further

8

Re: Arrays of buttons

var B: TComponent;
for i: = 1 to 7 do begin
B: = FindComponent (' Button ' +IntToStr (i));
if B is TButton then TComponent (B).Caption: = raduga [i];
end;

9

Re: Arrays of buttons

10

Re: Arrays of buttons

I am possible somewhere wildly  but he writes [Error] Unit1.pas (51): Undeclared identifier: ' Caption'

procedure TForm1.FormCreate (Sender: TObject);
var B: TComponent;
i:integer;
begin
for i: = 1 to 7 do begin
B: = FindComponent (' Button ' +IntToStr (i));
if B is TButton then TComponent (B).Caption: = raduga [i];
end;
end;
end.

11

Re: Arrays of buttons

temir123 wrote:

I am possible somewhere wildly  but he writes [Error] Unit1.pas (51): Undeclared identifier: ' Caption'
procedure TForm1.FormCreate (Sender: TObject);
var B: TComponent;
i:integer;
begin
for i: = 1 to 7 do begin
B: = FindComponent (' Button ' +IntToStr (i));
if B is TButton then TComponent (B).Caption: = raduga [i];
end;
end;
end.

1) Throw out the array (array of TButton) - it is not necessary to you.
2)
if (B is TButton) then TButton (B).Caption: = raduga [i];

12

Re: Arrays of buttons

Thanks, but at me a question, it really to make by means of an array of buttons, it is simple at me .

13

Re: Arrays of buttons

button1.color: = clRed;
button2.color: = clBlue;
Etc.

14

Re: Arrays of buttons

temir123 wrote:

thanks, but at me a question, it really to make by means of an array of buttons, it is simple at me .

Buttons [1]: =Button1;
Buttons [2]: =Button2;
Buttons [3]: =Button3;
...

15

Re: Arrays of buttons

temir123 wrote:

thanks, but at me a question, it really to make by means of an array of buttons, it is simple at me .

PosLeft: = 100;//for example
for i: = 1 to Length (Button)
do begin
Button [i]: =TButton. Create (Form1);
Button [i].Parent: = Form1;
Button [i].Left: = PosLeft;
Button [i].Top: = 5 + (Button [i].Height+5) * (i-1);
Button [i].Caption: = raduga [i];
end;

Something similar...

16

Re: Arrays of buttons

temir123;