FeedLoad example for C++ Builder
This example uses StartFeedLoad, FeedLoad and StopFeedLoad and loads a file through a buffer to simulate receiving a transmitted image.
void __fastcall TForm1::FeedLoadClick(TObject *Sender)
{
const int BUFFERSIZE = 1000;
void *MyBufferPtr=NULL;
int BytesRead, FileHandle;
/* 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)
{
ShowMessage("Error in StartFeedLoad !");
goto quit_function;
}
/* Use FeedLoad in a loop to load the file into the bitmap.*/
do
{
/* read from the file*/
BytesRead = FileRead(FileHandle, MyBufferPtr, BUFFERSIZE );
if( Lead1->FeedLoad(MyBufferPtr, BytesRead) != SUCCESS)
{
ShowMessage("Error in FeedLoad !");
goto quit_function;
}
} while (BytesRead > 0);
/* Finish the file-load process.*/
if( Lead1->StopFeedLoad() != SUCCESS)
ShowMessage("Error in StopFeedLoad !");
quit_function:
/* Close the file.*/
if(MyBufferPtr)
SysFreeMem(MyBufferPtr);
FileClose(FileHandle);
}
ShowMessage(MsgStr);