# Who can help me with this easy problem?

[b][red]This message was edited by the Moderator at 2002-4-17 4:41:41[/red][/b][hr]
Can you help me?
I have a program that does something like this:
[code]
begin
Card1.Value := Random(13)+1;
Card2.Value := Random(13)+1;
...
Card52.Value := Random(13)+1;
end;
[/code]

But I want this:
[code]
var
i: Integer;
begin
For i := 1 to 52 do begin
? Card + i ?.Value := Random(13)+1
end;
end;
[/code]

• : Can you help me?
: I have a program that does something like this:
: [code]
: begin
: Card1.Value := Random(13)+1;
: Card2.Value := Random(13)+1;
: ...
: Card52.Value := Random(13)+1;
: end;
: [/code]
:
: But I want this:
: [code]
: var
: i: Integer;
: begin
: For i := 1 to 52 do begin
: ? Card + i ?.Value := Random(13)+1
: end;
: end;
: [/code]
:

Make Card? an array Card[1..52] then you can do like this:

[code]
var
i: Integer;
begin
For i := 1 to 52 do Card[i].Value := Random(13)+1;
end;
[/code]

PS. Don't forget to close your [b]code[/b] tag with [b]/code[/b], it saves other people from correcting your misakes.
[hr]
[italic][red]N[/red][blue]et[/blue][red]G[/red][blue]ert[/blue][/italic]

• : : Can you help me?
: : I have a program that does something like this:
: : [code]
: : begin
: : Card1.Value := Random(13)+1;
: : Card2.Value := Random(13)+1;
: : ...
: : Card52.Value := Random(13)+1;
: : end;
: : [/code]
: :
: : But I want this:
: : [code]
: : var
: : i: Integer;
: : begin
: : For i := 1 to 52 do begin
: : ? Card + i ?.Value := Random(13)+1
: : end;
: : end;
: : [/code]
: :
:
: Make Card? an array Card[1..52] then you can do like this:
:
: [code]
: var
: i: Integer;
: begin
: For i := 1 to 52 do Card[i].Value := Random(13)+1;
: end;
: [/code]
:
: PS. Don't forget to close your [b]code[/b] tag with [b]/code[/b], it saves other people from correcting your misakes.
: [hr]
: [italic][red]N[/red][blue]et[/blue][red]G[/red][blue]ert[/blue][/italic]
:
:

This doesn't work because Card is a component.
I have on my form 52 components TCard (name: Card1, Card2, ...) and
I want to edit the Value (property) of al those components
• : : : Can you help me?
: : : I have a program that does something like this:
: : : [code]
: : : begin
: : : Card1.Value := Random(13)+1;
: : : Card2.Value := Random(13)+1;
: : : ...
: : : Card52.Value := Random(13)+1;
: : : end;
: : : [/code]
: : :
: : : But I want this:
: : : [code]
: : : var
: : : i: Integer;
: : : begin
: : : For i := 1 to 52 do begin
: : : ? Card + i ?.Value := Random(13)+1
: : : end;
: : : end;
: : : [/code]
: : :
: :
: : Make Card? an array Card[1..52] then you can do like this:
: :
: : [code]
: : var
: : i: Integer;
: : begin
: : For i := 1 to 52 do Card[i].Value := Random(13)+1;
: : end;
: : [/code]
: :
: : PS. Don't forget to close your [b]code[/b] tag with [b]/code[/b], it saves other people from correcting your misakes.
: : [hr]
: : [italic][red]N[/red][blue]et[/blue][red]G[/red][blue]ert[/blue][/italic]
: :
: :
:
: This doesn't work because Card is a component.
: I have on my form 52 components TCard (name: Card1, Card2, ...) and
: I want to edit the Value (property) of al those components
:
If the TCard.Value is typed as a TCardValue, then this code might do the trick:
[code]
var
i: Integer;
begin
For i := 0 to Form1.ComponentCount-1 do
if Form1.Components[i] is TCard then
(Form1.Components[i] as TCard).Value := TCardValue(Random(13));
end;
[/code]
This code searches through all the components on Form1, and if it is a TCard component, it changes the Value. The change involves converting an integer to a TCardValue.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!