notify_implementation_example.cpp
This small example demonstrates how the class ReadNotification could be used to provide feedback to a user interface for lengthy read operations.
#include <VCL.h>
#include <IBK_stopwatch.h>
#include "delphin5_output.h"
class NotifyUI : public DELPHIN5_OUTPUT_FILE_FILTERS::ReadNotification {
public:
NotifyUI(TMemo * m, unsigned int line_num) : memo(m), li(line_num) {}
virtual void notify() {
if (watch.difference() < 500) return;
watch.start();
AnsiString text = memo->Lines->Strings[li];
memo->Lines->Strings[li] = text + ".";
Application->ProcessMessages();
}
TMemo * memo;
unsigned int li;
IBK::StopWatch watch;
};
... other code ...
for (int i=0; i<=num_files; ++i) {
AnsiString fname = m_files[i];
memo->Lines->Add("Converting '" + ExtractFileName(fname) + "'...");
Application->ProcessMessages();
NotifyUI n(memo, i);
Delphin5OutputData outdata;
string err_msg;
if (!outdata.read(fname.c_str(), err_msg, &n)) {
MessageDlg("Cannot read output file '"+fname+"'!", mtError, TMsgDlgButtons() << mbOK, 0);
continue;
}
}