Ver Mensaje Individual
  #1  
Antiguo 15-05-2012
angelp4492 angelp4492 is offline
Miembro
 
Registrado: dic 2007
Posts: 99
Reputación: 0
angelp4492 cantidad desconocida en este momento
[error] Value be beetween 0 and 65535

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; // 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.
Responder Con Cita