Einzelnen Beitrag anzeigen

busybyte

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

Re: problem mit dynamischem array

  Alt 20. Feb 2008, 21:56
Delphi-Quellcode:
unit jpganzeigen02;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    FileListBox1: TFileListBox;
    Image1: TImage;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  public
   Function getZufall(bildanzahl_:integer):integer;
   Function debugrandoms(L1_,BildNr_:integer):TStrings;
   procedure jpeganzeigen(dateiname:TFilename; endung:string);
   Procedure iniRandoms(L1_:integer);
 { Public-Deklarationen }
  end;

var Form1: TForm1;

implementation {$R *.dfm}

var bmp: TBitmap;
    bildanzahl:integer;
    randoms:array of integer;
 TestS:string;
 Testi:integer;


Procedure TForm1.iniRandoms(L1_:integer);
Var cnt1:integer;
begin
for cnt1:=0 to L1_-1 do randoms[cnt1]:=cnt1;
bildanzahl:=L1_;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;

with Memo1 do
begin
Align:=alBottom;
Scrollbars:=ssBoth;
end;

with filelistbox1 do
begin
Directory:='C:\Windows';//Eigene Dateien\Eigene Bilder\';
Mask:='*.bmp;*.jpg;*.jpeg';

 if Items.Count>1 then
 begin
 setlength(randoms,Items.Count); //Edit
 iniRandoms(items.count);
 end;

end;


//randoms[11]:=11;
end;//procedure



Function TForm1.debugrandoms(L1_,BildNr_:integer):TStrings;
Var cnt1:integer;
begin
Result:=TStringlist.Create;
Result.add('BildNr: '+inttostr(BildNr_));
//Länge überschritten ? wenn ja dann reduzieren
while (L1_>Length(randoms)-1) do L1_:=High(randoms);

  for cnt1:=0 to L1_-1 do
  Result.add('Randoms' +inttostr(cnt1)+': '+inttostr(randoms[cnt1]));
  Result.add('*** end of debug ***');
end;


Function TForm1.getZufall(bildanzahl_:integer):integer;
begin
  
  Result:=Random(bildanzahl_); //Edit;
  while Result>high(randoms) do Result:=random(bildanzahl_); //Edit
end;


procedure TForm1.Button1Click(Sender: TObject);
var dateiname,endung:string;
    fi,fa,fb,zufall,bildnr:integer;
begin

  zufall:=GetZufall(bildanzahl);
  bildnr:=randoms[zufall];
  //debug anzeigen
  memo1.lines.Assign(DebugRandoms(filelistbox1.Items.count-1,bildnr));

  dateiname:=filelistbox1.items[bildnr];
  endung:=ExtractFileExt(dateiname);
  jpeganzeigen(dateiname,endung);


  randoms[zufall]:=randoms[bildanzahl-1];
  dec(bildanzahl);
   if bildanzahl<0 then iniRandoms(filelistbox1.items.count);
//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;

end.
I love DiscCat
  Mit Zitat antworten Zitat