Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  3 788

•  TDictionary Custom Sort  5 902

•  Fast Watermark Sources  5 703

•  3D Designer  8 478

•  Sik Screen Capture  6 037

•  Patch Maker  6 481

•  Айболит (remote control)  6 474

•  ListBox Drag & Drop  5 338

•  Доска для игры Реверси  94 949

•  Графические эффекты  6 677

•  Рисование по маске  5 801

•  Перетаскивание изображений  4 861

•  Canvas Drawing  5 236

•  Рисование Луны  4 959

•  Поворот изображения  4 505

•  Рисование стержней  3 187

•  Paint on Shape  2 434

•  Генератор кроссвордов  3 308

•  Головоломка Paletto  2 619

•  Теорема Монжа об окружностях  3 403

•  Пазл Numbrix  2 249

•  Заборы и коммивояжеры  2 909

•  Игра HIP  1 879

•  Игра Go (Го)  1 795

•  Симулятор лифта  2 131

•  Программа укладки плитки  1 860

•  Генератор лабиринта  2 296

•  Проверка числового ввода  1 985

•  HEX View  2 294

•  Физический маятник  1 958

 
скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Скопировать файл с заполнением своего ProgressBara



Автор: Xavier Pacheco

{
Copyright © 1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
}

unit MainFrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, ComCtrls, Gauges;

type
  TMainForm = class(TForm)
    prbCopy: TProgressBar;
    btnCopy: TButton;
    procedure btnCopyClick(Sender: TObject);
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.btnCopyClick(Sender: TObject);
var
  SrcFile, DestFile: file;
  BytesRead, BytesWritten, TotalRead: Integer;
  Buffer: array[1..500] of byte;
  FSize: Integer;
begin
  { Assign both the source and destination files to their
    respective file variables }
  AssignFile(SrcFile, 'srcfile.tst');
  AssignFile(DestFile, 'destfile.tst');
  // Open the source file for read access.
  Reset(SrcFile, 1);
  try
    // Open destination file for write access.
    Rewrite(DestFile, 1);
    try
      { Encapsulate this into a try..except so that we can erase the file if
        an error occurs. }
      try
        // Initialize total bytes read to zero.
        TotalRead := 0;
        // Obtain the filesize of the source file
        FSize := FileSize(SrcFile);
        { Read SizeOf(Buffer) bytes from the source file
          and add these bytes to the destination file. Repeat this
          process until all bytes have been read from the source
          file. A progress bar is provided to show the progress of the
          copy operation. }
        repeat
          BlockRead(SrcFile, Buffer, SizeOf(Buffer), BytesRead);
          if BytesRead > 0 then
          begin
            BlockWrite(DestFile, Buffer, BytesRead, BytesWritten);
            if BytesRead <> BytesWritten then
              raise Exception.Create('Error copying file')
            else
            begin
              TotalRead := TotalRead + BytesRead;
              prbCopy.Position := Trunc(TotalRead / Fsize) * 100;
              prbCopy.Update;
            end;
          end
        until BytesRead = 0;
      except
        { On an exception, erase the destination file as it may be
          corrupt. Then re-raise the exception. }
        Erase(DestFile);
        raise;
      end;
    finally
      CloseFile(DestFile); // Close the destination file.
    end;
  finally
    CloseFile(SrcFile); // Close the source file.
  end;
end;

end.




Похожие по теме исходники

Чтение PSD файлов

Шифратор файлов

Разбиение файла на части

Поиск файлов

 

FileMan (менеджер файлов)

Поиск открытых файлов

Текст внутри файла




Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте