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
MyBufferPtr: Pointer;
BytesRead: Longint;
FileHandle: integer;
label quit_function;
begin
{ 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( 'c:\lead\images\image1.cmp', fmOpenRead );
{ Set PaintWhileLoad so that we can watch the progress.}
Lead1.PaintWhileLoad := True;
{ Initialize the file-load process.}
{ Specify the default bits per pixel and first page}
If Lead1.StartFeedLoad(0, 0, 1) <> SUCCESS 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}
If Lead1.FeedLoad(MyBufferPtr, BytesRead) <> SUCCESS Then
begin
MessageDlg ('Error in FeedLoad !', mtError, [mbOK], 0);
GoTo quit_function
end;
Until BytesRead <= 0;
{ Finish the file-load process.}
If Lead1.StopFeedLoad() <> SUCCESS Then
MessageDlg ('Error in StopFeedLoad !', mtError, [mbOK], 0);
quit_function:
{ Close the file.}
FreeMem(MyBufferPtr);
FileClose( FileHandle );
end;