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.
Código Delphi
[-]
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; BytesPreviouslyDownloaded: int64; BytesDownloaded: int64;
IndyInAThread: TIndyInAThread; constructor create (URL_ :string; Listview_ : TListView; unique_ID:integer);
procedure addToView;
procedure transferfile;
end;
type
TForm1 = class(TForm)
ListView1: TListView;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
fNextUniqueID: integer;
public
DownloadList : TObjectList;
function GetNextUniqueID: integer;
function IndexOfDownloadableFile(UniqueID_: integer): integer; 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_;
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);
end;
procedure TTransferFile.IndyInAThreadComplete(sender: TObject);
begin
if (Sender = IndyInAThread) then
IndyInAThread := nil;
end;
function Tform1.GetNextUniqueID: integer;
begin
result := fNextUniqueID; 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('');
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
TTransferFile(DownloadList[i]).BytesDownloaded := TTransferFile(DownloadList[i]).BytesPreviouslyDownloaded;
TTransferFile(DownloadList[i]).TotalFileSize := TTransferFile(DownloadList[i]).BytesPreviouslyDownloaded + totalbytes_;
TTransferFile(DownloadList[i]).ProgressBar.Position := 0;
TTransferFile(DownloadList[i]).ProgressBar.Max := TTransferFile(DownloadList[i]).TotalFileSize; aquí falla
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.