PDA

Ver la Versión Completa : [error] Value be beetween 0 and 65535


angelp4492
15-05-2012, 19:56:48
Hola intento crear una barra de progreso en un listview y al recibir los datos y asirnarlos al listview me sale el error Value be beetween 0 and 65535.

esta es la unidad.


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,UnitDownload, ComCtrls, StdCtrls,Contnrs;

type TTransferFile = class
private
procedure IndyInAThreadComplete(sender: TObject);
public
ProgressBar : TProgressBar;
ListView : TListView;
Item : TListItem;
Url : string;
Filename : string;
TempFilename : string;
Path : string;
UniqueID : Integer;
TotalFileSize: int64; // use 0 if unknown
BytesPreviouslyDownloaded: int64; // eg. if resuming
BytesDownloaded: int64;
//State: TDownloadStateForImages; //para las imagenes
IndyInAThread: TIndyInAThread; //variable del thread
constructor create (URL_ :string; Listview_ : TListView; unique_ID:integer);
procedure addToView;
procedure transferfile;
//procedure UpdateDatos;
end;

type
TForm1 = class(TForm)
ListView1: TListView;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
fNextUniqueID: integer;
{ Private declarations }
public
{ Public declarations }
DownloadList : TObjectList;
function GetNextUniqueID: integer;
function IndexOfDownloadableFile(UniqueID_: integer): integer; // returns the index of the downloadable file that matches this uniqueid
Procedure HTTPClientDownloadBeginWork(var Msg:TMessage);Message WM_HTTPClientDownloadBeginWork;

end;
type TDownloadfile = class (TObject)
private
public
Url : string;
UniqueID : Integer;
constructor create (URL_ :string; uniqueID_:integer);
end;

var
Form1: TForm1;

implementation

constructor TDownloadFIle.create (URL_ :string; uniqueID_:integer);
begin
inherited Create;
URL := URL_;
UniqueID := UniqueID_;
//State := si_Blank;

end;

constructor TTransferFile.create (URL_ :string; Listview_ : TListView; unique_ID:integer);
begin
inherited Create;
URL := URL_;
Listview := Listview_;
UniqueID := Unique_ID;
ProgressBar := TProgressBar.Create(nil);

//State := si_Blank;

end;
procedure TTransferFile.IndyInAThreadComplete(sender: TObject);
begin
if (Sender = IndyInAThread) then
IndyInAThread := nil;
end;

function Tform1.GetNextUniqueID: integer;
begin
result := fNextUniqueID;//obtenemos un ID por cada thread
inc(fNextUniqueID);
end;

function TForm1.IndexOfDownloadableFile(UniqueID_: integer): integer;
var
i: integer;
begin
result := -1;
i := 0;
while ( (result = -1) and (i < Downloadlist.Count) ) do
begin
if TDownloadFile(DownloadList[i]).UniqueID = UniqueID_ then
result := i
else
inc(i);
end;
end;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
DownloadList:=TObjectList.Create;
fNextUniqueID:=0;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
newlistitem : TListItem;
enlace :string;
download : TDownloadfile;
transferfile : TTransferfile;
i: Integer;

begin
enlace := 'http://www.rtve.es/resources/TE_SAMARE/mp4/6/0/1334332703906.mp4';
download :=TDownloadfile.create(enlace,GetNextUniqueID);
DownloadList.Add(download);
Transferfile:= TTransferFile.create(TDownloadfile(DownloadList[0]).Url,ListView1,TDownloadfile(DownloadList[0]).UniqueID);
transferfile.addToView;
transferfile.transferfile;
end;

procedure TTransferFile.addToView;
var
RectProg: TRect;
begin
item := ListView.items.add;
item.Caption := Url;
Item.SubItems.Add('');
Item.SubItems.Add('');


//if es_descarga then Item.ImageIndex := 9
//else Item.ImageIndex := 10;

Item.Data := self;
RectProg := Item.DisplayRect(drBounds);
RectProg.Left := RectProg.Left + ListView.Columns[0].Width;
RectProg.Right := RectProg.Left + ListView.Columns[1].Width;
ProgressBar.BoundsRect := RectProg;
progressBar.Parent := ListView;

end;
Procedure Tform1.HTTPClientDownloadBeginWork(var Msg:TMessage);
var
uniqueid_: integer;
totalbytes_: integer;
i: integer;
begin
uniqueid_ := Msg.wparam;
totalbytes_ := Msg.LParam;

i := IndexOfDownloadableFile(uniqueid_);
if i <> -1 then
begin

//ShowMessage(IntToStr(totalbytes_));
TTransferFile(DownloadList[i]).BytesDownloaded := TTransferFile(DownloadList[i]).BytesPreviouslyDownloaded;
TTransferFile(DownloadList[i]).TotalFileSize := TTransferFile(DownloadList[i]).BytesPreviouslyDownloaded + totalbytes_;
//TDownloadFile(DownloadaList[i]).State := si_Downloading_Animation1;
TTransferFile(DownloadList[i]).ProgressBar.Position := 0;
TTransferFile(DownloadList[i]).ProgressBar.Max := TTransferFile(DownloadList[i]).TotalFileSize; aquí falla
//ListviewTransfer.Repaint;

end;
end;



procedure TTransferfile.transferfile;
begin
Self.BytesPreviouslyDownloaded:=0;
IndyInAThread := TIndyInAThread.Create(Self.Url,'c:\prueba.mp4',false,8080,'127.0.0.1',Self.UniqueID,form1.handle,Ind yInAThreadComplete);
ShowMessage(Self.Url);
end;



end.



alguien se le ocurre alguna idea de que estoy haciendo mal.

luisgutierrezb
15-05-2012, 21:01:18
Pues que de seguro el total del archivo debe ser mayor a 65535, lo que puedes hacer es dividir el tamaño del archivo entre 100, y cada vez que pase esa cantidad de bytes, aumentas en el progress bar

angelp4492
15-05-2012, 21:08:24
Pues que de seguro el total del archivo debe ser mayor a 65535, lo que puedes hacer es dividir el tamaño del archivo entre 100, y cada vez que pase esa cantidad de bytes, aumentas en el progress bar

Si pero porqué cuando coloco un progresbar en el formulario si me acepta valores mayores de 65535, y sin embargo creándolo desde una clase no?

ecfisa
16-05-2012, 11:43:57
Si pero porqué cuando coloco un progresbar en el formulario si me acepta valores mayores de 65535, y sin embargo creándolo desde una clase no?
Hola angelp4492.

No creo que ese sea el motivo.

Para verificar que, independientemente de donde se lo cree, acepta el máximo valor posible para una propiedad de tipo Integer podés hacer:

...
type
TDummyClass = class(TObject)
public
ProgressBar: TProgressBar;
constructor Create(AOwner: TComponent);
destructor Destroy;
end;
TForm1 = class(TForm)
...

implementation

{ TDummyClass }
constructor TDummyClass.Create(AOwner: TComponent);
begin
inherited Create;
ProgressBar:= TProgressBar.Create(nil);
ProgressBar.Max:= MaxInt
end;

destructor TDummyClass.Destroy;
begin
ProgressBar.Free;
inherited Destroy
end;

{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
DC: TDummyClass;
begin
DC:= TDummyClass.Create(Self);
try
//...
DC.ProgressBar.Parent:= Self;
ShowMessage(IntToStr(DC.ProgressBar.Max))
finally
DC.Free
end
end;
...


Saludos.

angelp4492
16-05-2012, 12:08:52
Ya lo tengo resuelto no estaba operando bien entre la clase tdownloadfile y ttransferfile, ahora ya si corre la barra de progreso y me acepta valores mayores de 65535. Gracias