Howdy, Stranger!

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

Categories

Who can help me with this easy problem?

TiteufTiteuf Member Posts: 20
[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]


Comments

  • netgertnetgert Member Posts: 331
    : 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]

  • TiteufTiteuf Member Posts: 20
    : : 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
  • zibadianzibadian Member Posts: 6,349
    : : : 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.
  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    ______ || http://forcoder.org || free video tutorials and ebooks about \ Ruby, Java, JavaScript, PHP, Perl, C++, C#, PL/SQL, Visual Basic, Assembly, MATLAB, Visual Basic .NET, Delphi, Scratch, Swift, Go, Python, Objective-C, R, C FoxPro, Awk, ABAP, Kotlin, LabVIEW, Scala, Bash, F#, Rust, Scheme, Clojure, Lua, Ada, Prolog, Hack, Apex, Julia, D, Transact-SQL, Crystal, Alice, SAS, Fortran, Lisp, VBScript, Dart, COBOL, Logo, ML, Erlang \ ___________

Sign In or Register to comment.