Losowanie

0

Jak napisać procedurę która będzie losowo wybierała plik w FileListBox i go zaznaczała? Plizzz. Help mi ;)

0

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, FileCtrl;

type
TForm1 = class(TForm)
Button1: TButton;
FileListBox1: TFileListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
a : integer;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
b : integer;
begin
filelistbox1.Directory := 'c:\windows';
b := filelistbox1.items.count - 1;

randomize;
a := random(b);
if a &lt 0 then
begin

end else
begin
filelistbox1.ItemIndex := a;
end;
end;

end.

0

Randomize;
f.Selected[Random(f.Count)] := True;

Gdzie f to nazwa komponentu.--Pozdrawiam!
Adam Boduch
www.4programmers.net

0

Adam Boduch napisał:
Randomize;
&gt f.Selected[Random(f.Count)] := True;
&gt
U mnie to nie dziala- wyskakuje "List index out of bounds ....." itp. Ja napisalem tak:

Randomize;
FileListBox1.ItemIndex:=Random(FIleListBox1.Items.Count);
--Pozdrawiam
Ojciec (Delphi/C++)

0

sprobuj to:

Randomize;
FileListBox1.ItemIndex:=Random(FIleListBox1.Items.Count-1)---=-=[ Delphi 3, 6 ]=-=-
-=-=-==[ LKS ]==-=-=-
-=[ [email protected] ]=-

0

Ojciec napisał:
Adam Boduch napisał:

Randomize;

f.Selected[Random(f.Count)] := True;

U mnie to nie dziala- wyskakuje "List index out of bounds ....." itp. Ja napisalem tak:

Randomize;
FileListBox1.ItemIndex:=Random(FIleListBox1.Items.Count);

Od tego odejmij 1. Po prostu losowalo Ci liczbe wieksza od liczby elementow...--Pozdrawiam!
Adam Boduch
www.4programmers.net

0

NAwet jak napisze
ListBOx1.Selected[0]:=True;
to przy 13 itemach pokazuje mi si ten blad. A LKS z tym Count-1 ma racje.
--Pozdrawiam
Ojciec (Delphi/C++)

1 użytkowników online, w tym zalogowanych: 0, gości: 1