Registriert seit: 3. Jan 2007
Ort: Dresden
3.443 Beiträge
Delphi 7 Enterprise
|
Re: Verschachtelte Schleifen - Gesamtfortschritt
27. Feb 2008, 16:37
Delphi-Quellcode:
SchritteGesamt:=Sectors div (Length(Buffer) div SectorSize) * FPassCount ;
SchritteAktuell:=Pos div (Length(Buffer) div SectorSize) +
Sectors div (Length(Buffer) div SectorSize) * Pass;
Prozent:=trunc((SchritteAktuell/SchritteGesamt) *100);
Funktioniert zumindest in meinem Beispiel:
Delphi-Quellcode:
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, MAth, CommCtrl;
type
TForm1 = class(TForm)
ProgressBar1: TProgressBar;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure getmsg(var msg:TMessage);message WM_User;
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type PContent=^TContent;
Tcontent=record
ProgressWnd:hwnd;
FormWnd:hwnd;
Sectors:integer;
SectorSize:integer;
FPassCount:integer;
LengthBuffer:integer;
end;
function test(aParam:PContent):integer;
var i,Pos,Pass:integer;
Param:TContent;
Prozent:integer;
SchritteGesamt,
Schritte:integer;
begin
Param:=aParam^;
dispose(aParam);
try
for Pass:=0 to param.FPassCount-1 do
begin
Pos:=0;
while Pos < param.Sectors do
begin
i:=Min(param.Sectors - Pos, param.LengthBuffer div param.SectorSize);
inc(Pos,i);
SchritteGesamt:=param.Sectors div (param.LengthBuffer div param.SectorSize) * Param.FPassCount ;
Schritte:=pos div (param.LengthBuffer div param.SectorSize) +
param.Sectors div (param.LengthBuffer div param.SectorSize)*Pass;
Prozent:=trunc((Schritte/SchritteGesamt) *100);
postmessage(param.ProgressWnd,PBM_SETPOS, Prozent, 0);
sleep(200);
end;
end;
finally
postmessage(param.ProgressWnd,PBM_SETPOS, 0, 0);
postmessage(param.FormWnd,WM_User,0,0);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var temp:cardinal;
Param:PContent;
begin
new(Param);
PAram.ProgressWnd:=progressbar1.Handle;
Param.FormWnd:=self.handle;
Param.Sectors:=20;
Param.SectorSize:=100;
Param.FPassCount:=4;
Param.LengthBuffer:=300;
BeginThread(nil,0,@test,param,0,temp);
Button1.Enabled:=false;
end;
procedure Tform1.getmsg(var msg:TMessage);
begin
Button1.Enabled:=true;
end;
end.
Dieser Beitrag ist für Jugendliche unter 18 Jahren nicht geeignet.
|
|
Zitat
|