FeedLoad example for Delphi
This example uses StartFeedLoad, FeedLoad, and StopFeedLoad and loads a file through a buffer to simulate receiving a transmitted image.
procedure TForm1.Button1Click(Sender: TObject);
Const BUFFERSIZE = 1000;
var
Buffer: Variant;
RasterVarBuffer: LEADRasterVariant;
MyBufferPtr: Pointer;
BytesRead: Longint;
FileHandle: integer;
RasterIO: LEADRasterIO;
i: Integer;
label quit_function;
begin
RasterIO:= CreateComObject (CLASS_LEADRasterIO) as LEADRasterIO;
RasterVarBuffer:= CoLEADRasterVariant.Create ( );
RasterVarBuffer.Type_:= VALUE_STRING;
Buffer:= VarArrayCreate([0, BUFFERSIZE-1], varByte);
{ Declare a buffer that you will use to feed the file-load process.}
MyBufferPtr := AllocMem(BUFFERSIZE);
{ Declare other local variables.}
{ Open an image file and get its length.}
FileHandle := FileOpen('v:\images\image1.cmp', fmOpenRead );
{ Set PaintWhileLoad so that we can watch the progress.}
LEADRasterView1.PaintWhileLoad := True;
{ Initialize the file-load process.}
{ Specify the default bits per pixel and first page}
if RasterIO.StartFeedLoad(LEADRasterView1.Raster,0, 0, 1) <> 0 Then
begin
MessageDlg ('Error in StartFeedLoad !', mtError, [mbOK], 0);
GoTo quit_function
end;
{ Use FeedLoad in a loop to load the file into the bitmap.}
repeat
BytesRead := FileRead(FileHandle, MyBufferPtr^, BUFFERSIZE ); { read from the file}
for i:= 0 to BytesRead-1 do
Buffer[i] := Byte((Pchar(MyBufferPtr)+i)^);
RasterVarBuffer.StringValue:= Buffer;
if RasterIO.FeedLoad(RasterVarBuffer, BytesRead) <> 0 Then
begin
MessageDlg ('Error in FeedLoad !', mtError, [mbOK], 0);
GoTo quit_function
end;
Until BytesRead <= 0;
{ Finish the file-load process.}
if RasterIO.StopFeedLoad() <> 0 Then
MessageDlg ('Error in StopFeedLoad !', mtError, [mbOK], 0);
quit_function:
{ Close the file.}
FreeMem(MyBufferPtr);
FileClose( FileHandle );
end;