planix
Technical User
- Dec 3, 2002
- 22
Hi,
I have a form with a multiple number of labels on it. Each label is named "l1" "l2" ... "ln". I need to select a label at random to display some text.
So I want to randomly generate a number between 1 and n - easy.
Then I want to use that number to point to the label with that number in it's name so as to change the caption property of that label... this bit I am not at all sure about.
My dummy code idea would look something like this...
But of course this is doomed to fail. So, does anyone know how I can do this?
Cheers
Alistair
Townsville, Qld
I have a form with a multiple number of labels on it. Each label is named "l1" "l2" ... "ln". I need to select a label at random to display some text.
So I want to randomly generate a number between 1 and n - easy.
Then I want to use that number to point to the label with that number in it's name so as to change the caption property of that label... this bit I am not at all sure about.
My dummy code idea would look something like this...
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
alabelobject: TLabel;
i: integer;
begin
alabelobject := TLabel.Create();
//randomly select one of the letters from the alphabet and //then display in the caption
Randomize;
i:=Random(48)
alabelobject.name(i).Caption := alphabet.Strings[Random(25)];
end;
But of course this is doomed to fail. So, does anyone know how I can do this?
Cheers
Alistair
Townsville, Qld