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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
library mon_udf;
uses
classes,
Windows,
ib_util;
type
Int = LongInt; // 32 bit signed
UInt = DWord; // 32 bit unsigned
Long = LongInt; // 32 bit signed
ULong = DWord; // 32 bit unsigned
Short = SmallInt;// 16 bit signed
UShort = Word; // 16 bit unsigned
Float = Single; // 32 bit
UChar = Byte; // 8 bit unsigned
ISC_LONG = Long; // 32 bit signed
UISC_LONG = ULong; // 32 bit unsigned
ISC_STATUS = Long; // 32 bit signed
UISC_STATUS = ULong; // 32 bit unsigned
Void = Pointer;
// Delphi "Pointer types"
PPChar = ^PChar;
PSmallInt = ^SmallInt;
PInt = ^Int;
PInteger = ^Integer;
PShort = ^Short;
PUShort = ^UShort;
PLong = ^Long;
PULong = ^ULong;
PFloat = ^Float;
PUChar = ^UChar;
PVoid = ^Pointer;
PDouble = ^Double;
PISC_LONG = ^ISC_LONG;
PUISC_LONG = ^UISC_LONG;
PISC_STATUS = ^ISC_STATUS;
PPISC_STATUS = ^PISC_STATUS;
PUISC_STATUS = ^UISC_STATUS;
TISC_BlobGetSegment = function(BlobHandle: PInt;
Buffer: PChar;
BufferSize: Long;
var ResultLength: Long): Short; cdecl;
TISC_BlobPutSegment = procedure(BlobHandle: PInt;
Buffer: PChar;
BufferLength: Short); cdecl;
TBlob = record
GetSegment : TISC_BlobGetSegment;
BlobHandle : PInt;
SegmentCount : Long;
MaxSegmentLength : Long;
TotalSize : Long;
PutSegment : TISC_BlobPutSegment;
end;
PBlob = ^TBlob;
function ReadBlob(Blob : PBlob) : integer; cdecl;
var bytes_read, bytes_left, total_bytes_read: Long;
st : String;
fs : TFileStream;
l : TStrings;
// total_written : long;
begin
Result := 0;
with Blob^ do
begin
SetString(st, nil, TotalSize);
total_bytes_read := 0; // total bytes read is 0.
bytes_left := TotalSize; // I have TotalSize bytes to read.
if (bytes_left > 0) then
begin
repeat
// Using BlobHandle, store at most "bytes_left" bytes in
// the buffer starting where I last left off
GetSegment(BlobHandle, @st[total_bytes_read + 1], bytes_left, bytes_read);
// Increment total_bytes_read by the number of bytes actually read.
Inc(total_bytes_read, bytes_read);
// Decrement bytes_left by the number of bytes actually read.
Dec(bytes_left, bytes_read);
until bytes_left <= 0;
fs:= TFileStream.Create('c:\fileblob.dat',fmCreate);
fs.Size := Blob^.TotalSize;
fs.Write(st,Blob^.TotalSize);
fs.Free;
l:= TStringList.Create;
l.Text:= st;
l.SaveToFile('c:\fileblob.txt');
l.Free;
Result := 1;
end;
end;
end;
exports
ReadBlob;
end. |
Partager