Einzelnen Beitrag anzeigen

busybyte

Registriert seit: 15. Sep 2006
165 Beiträge
 
#14

Re: problem mit dynamischem array

  Alt 20. Feb 2008, 20:51
Dein Code ist Horror,ich habe ihn in soweit korrigiert ,das er für mich halbwegs einen Sinn
ergeben könnte.

Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var fa:integer;
begin
randomize;
zaehl:=0;
filelistbox1.Directory:='C:\';//Eigene Dateien\Eigene Bilder\';
filelistbox1.Mask:='*.bmp;*.jpg;*.jpeg';

if filelistbox1.Items.Count>1 then
begin
setlength(randoms,filelistbox1.Items.Count); //Edit
bildanzahl:=filelistbox1.items.count; //Edit
end;
ca:=0;
memo1.lines.add(inttostr(filelistbox1.Items.count));
for fa:=low(randoms) to high(randoms) do
randoms[fa]:=fa;
//randoms[11]:=11;
end;//procedure

procedure TForm1.Button1Click(Sender: TObject);
var dateiname,endung:string;
    fi,fa,fb,zufall,bildnr:integer;
begin
//for fa:=0 to filelistbox1.items.count-1 do begin



//Edit
  zufall:=bildanzahl;
  while zufall>high(randoms) do Zufall:=random(bildanzahl); //Edit

//while (zufall>Length(randoms)-1) do exit;
  bildnr:=randoms[zufall];

  //Edit
  for fa:=0 to filelistbox1.Items.count-1 do
  begin
  test:=inttostr(randoms[fa]);
  memo1.lines.add(inttostr(randoms[fa])+' '+inttostr(bildnr));
  end;


 //Letztes Edit memo1.lines.add(test+' '+inttostr(bildnr));
test:='';
  randoms[zufall]:=randoms[bildanzahl-1]; //Edit
  inc(bildanzahl,-1);
  if bildanzahl<0 then begin
    for fb:=0 to filelistbox1.items.count-1 do randoms[fb]:=fb;
    bildanzahl:=filelistbox1.items.count;
  end;

////EDIT
while (bildnr<0) or (bildnr>filelistbox1.items.count-1) do exit;

dateiname:=filelistbox1.items[bildnr];

for fi:=length(dateiname)-3 to length(dateiname) do endung:=endung+dateiname[fi];
endung:=lowercase(endung);
jpeganzeigen(dateiname,endung);
//inc(zaehl);
end;//procedure

procedure TForm1.jpeganzeigen(dateiname:TFilename;endung:string);
var jpeg: TJPEGImage;
begin
bmp := TBitmap.Create;
//Bitmaps anzeigen
if endung='.bmpthen bmp.loadfromfile(dateiname);
//Jpegs anzeigen
if (endung='.jpg') or (endung='jpeg') then begin
  jpeg := TJPEGImage.Create;
  try
    jpeg.CompressionQuality := 100; {Default Value}
    jpeg.LoadFromFile(dateiname);
    bmp.Assign(jpeg);
  finally
    jpeg.Free
  end;
end;//if
image1.picture.bitmap:=bmp;
image1.AutoSize:=true;
bmp.free;
end;//procedure;
I love DiscCat
  Mit Zitat antworten Zitat