1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| unit StreamEx;
interface
Uses
Windows, Classes,
DB;
type
TStreamEx = class(TMemoryStream)
private
FOnProgress : TNotifyEvent;
procedure Progress(Sender : TObject);
public
property OnProgress : TNotifyEvent Read FOnProgress Write FOnProgress;
function CopyFrom(Source: TStream; Count: Int64): Int64;overload;
constructor Create();
end;
TBlobFieldEx = class(TBlobField)
procedure SaveToStream(Stream: TStreamEx);overload;
end;
implementation
function TStreamEx.CopyFrom(Source: TStream; Count: Int64): Int64;
Const
MaxBufSize = $F000;
Var
BufSize, N : Integer;
Buffer : PChar;
Begin
If Count = 0 Then
Begin
Source.Position := 0;
Count := Source.Size;
End;
Result := Count;
If Count > MaxBufSize Then
BufSize := MaxBufSize
Else
BufSize := Count;
GetMem(Buffer, BufSize);
Try
While Count <> 0 Do
Begin
If Count > BufSize Then
N := BufSize
Else
N := Count;
Source.ReadBuffer(Buffer^, N);
WriteBuffer(Buffer^, N);
Dec(Count, N);
// A chaque buffer copié, Progress est appelée
Progress(Self);
End;
Finally
FreeMem(Buffer, BufSize);
End;
end;
constructor TStreamEx.Create;
begin
end;
procedure TStreamEx.Progress(Sender: TObject);
begin
if Assigned(FOnProgress) then
FOnProgress(Sender);
end;
{ TBlobFieldEx }
procedure TBlobFieldEx.SaveToStream(Stream: TStreamEx);
var
BlobStream: TStream;
begin
BlobStream := DataSet.CreateBlobStream(Self, bmRead);
try
Stream.CopyFrom(BlobStream, 0);
finally
BlobStream.Free;
end;
end;
end. |
Partager