 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Vincent Guest
|
Posted: Thu Jun 17, 2004 10:12 am Post subject: TImage::OnProgress |
|
|
Little problem :
I just want to show a progress bar when loading a image into a Timage.
But it doesn't work,
here's the code
void __fastcall TForm5::Image2Progress(TObject *Sender,
TProgressStage Stage, BYTE PercentDone, bool RedrawNow,
const TRect &R, const AnsiString Msg)
{
switch (Stage)
{
case psStarting:
CGauge1->Progress=0;
CGauge1->Visible=true;
break;
case psRunning:
CGauge1->Progress=PercentDone;
break;
case psEnding:
CGauge1->Visible=false;
break;
}
}
using breakpoint i can see that i never enter in the routine.
I thought that this routine will called "periodically" when i load a
file intio my image with :
Image2->Picture->Bitmap->LoadFromFile(FileListBox1->FileName);
Any Idea
Thanks Vincent
|
|
| Back to top |
|
 |
nicolasr Guest
|
Posted: Thu Jun 17, 2004 1:34 pm Post subject: Re: TImage::OnProgress |
|
|
Hi,
I guess that this event is only used with image types that need
to decompress the data before displaying it.
Try
#include <jpeg.hpp> //needed to register jpg file type
....
Image2->Picture->LoadFromFile(FileListBox1->FileName);
....
with a large jpg file and see if the handler is then called.
Nick
| Quote: | Little problem :
I just want to show a progress bar when loading a image into a Timage.
But it doesn't work,
here's the code
void __fastcall TForm5::Image2Progress(TObject *Sender,
TProgressStage Stage, BYTE PercentDone, bool RedrawNow,
const TRect &R, const AnsiString Msg)
{
switch (Stage)
{
case psStarting:
CGauge1->Progress=0;
CGauge1->Visible=true;
break;
case psRunning:
CGauge1->Progress=PercentDone;
break;
case psEnding:
CGauge1->Visible=false;
break;
}
}
using breakpoint i can see that i never enter in the routine.
I thought that this routine will called "periodically" when i load a
file intio my image with :
Image2->Picture->Bitmap->LoadFromFile(FileListBox1->FileName);
Any Idea
Thanks Vincent
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Jun 17, 2004 5:38 pm Post subject: Re: TImage::OnProgress |
|
|
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote
| Quote: | I guess that this event is only used with image types
that need to decompress the data before displaying it.
|
The OnProgress event is optional in TGraphic classes. They are not required
to trigger it during loading/saving. In fact, none of the default graphic
classes (TBitmap, TIcon, TMetaFile, etc) use it at all.
Gambit
|
|
| Back to top |
|
 |
Andy Guest
|
Posted: Mon Aug 02, 2004 7:11 am Post subject: Re: TImage::OnProgress |
|
|
Hi Vincent,
I had the same problem showing a progress bar when loading a large RTF-File into a TRichEdit with LoadingFromFile.
I found this solution:
First I opened the file with a TFileStream and loaded the data with the LoadFromStream function (which also exists for the TGraphic class).
LoadFromStream access the stream data via the Read method, which is a virtual Method of TFileStream.
So I wrote my own class TMyFileStream derived from TFileStream and overloaded the Read methode:
class TMyFileStream : public TFileStream
{
public:
TProgressBar* progressBar;
public:
TMyFileStream (const String fileName, Word Mode,
TProgressBar* progBar) :
TFileStram (fileName, Mode),
progressBar (progBar) {};
virtual int __fastcall Read(void *Buffer, int Count)
{
progressBar->Position = (float)(Position/Size)*
progressBar->Max;
Application->ProcessMessages ();
return TFileStream::Read (Buffer, Count);
}
}
So whenever LoadFromStream is reading new data via Read I can update the ProgressBar.
Best regards
Andy
Vincent <vincent.vandendaele (AT) trump (DOT) be> wrote:
| Quote: | Little problem :
I just want to show a progress bar when loading a image into a Timage.
But it doesn't work,
here's the code
void __fastcall TForm5::Image2Progress(TObject *Sender,
TProgressStage Stage, BYTE PercentDone, bool RedrawNow,
const TRect &R, const AnsiString Msg)
{
switch (Stage)
{
case psStarting:
CGauge1->Progress=0;
CGauge1->Visible=true;
break;
case psRunning:
CGauge1->Progress=PercentDone;
break;
case psEnding:
CGauge1->Visible=false;
break;
}
}
using breakpoint i can see that i never enter in the routine.
I thought that this routine will called "periodically" when i load a
file intio my image with :
Image2->Picture->Bitmap->LoadFromFile(FileListBox1->FileName);
Any Idea
Thanks Vincent
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Aug 02, 2004 8:29 am Post subject: Re: TImage::OnProgress |
|
|
"Andy" <Andy-Bauer (AT) gmx (DOT) de> wrote
| Quote: | So I wrote my own class TMyFileStream derived from
TFileStream and overloaded the Read methode:
|
Just as a suggestion, I would recommend exposing an OnProgress event for
that class rather than having it update a progress bar directly. That will
make the code more flexible so that you can use the same code for different
purposes. For example:
enum TFileStreamReadProgressStage { psFileReadStarting, psFileReading,
psFileReadEnding };
typedef void __fastcall (__closure *TMyFileStreamProgress)(TObject
*Sender, TFileStreamReadProgressStage Stage, Byte PercentDone);
class TMyFileStream : public TFileStream
{
protected:
TMyFileStreamProgress FOnProgress;
bool FStarting;
Byte FLastPercent;
public:
__fastcall TMyFileStream(const AnsiString &FileName, Word Mode)
: TFileStream(FileName, Mode), FStarting(true), FLastPercent(0)
{
}
virtual __fastcall ~TMyFileStream()
{
if( (FLastPercent < 100) && (FOnProgress) )
FOnProgress(this, psFileReadEnding, 100);
}
virtual int __fastcall Read(void *Buffer, int Count)
{
if( bStarting )
{
if( FOnProgress )
FOnProgress(this, psFileReadStarting, 0);
bStarting = false;
}
int Result = TFileStream::Read(Buffer, Count);
if( FOnProgress )
{
Byte CurrentProgress = ((Position*100)/Size);
if( CurrentProgress != FLastPercent )
{
FLastPercent = CurrentProgress;
FOnProgress(this, (CurrentProgress < 100) ?
psFileReading : psFileReadEnding, CurrentProgress);
}
}
return Result;
}
__property TMyFileStreamProgress OnProgress = {read=FOnProgress,
write=FOnProgress};
};
void __fastcall TForm1::LoadRichEdit()
{
TMyFileStream *Strm = new TMyFileStream("somefile", fmOpenRead |
fmShareDenyWrite);
try
{
Strm->OnProgress = RichEditLoadProgress;
RichEdit1->LoadFromStream(Strm);
}
__finally{
delete Strm;
}
}
void __fastcall TForm1::RichEditLoadProgress(TObject *Sender,
TFileStreamReadProgressStage Stage, Byte PercentDone)
{
switch( Stage )
{
case psFileReadStarting:
ProgressBar1->Position = 0;
ProgressBar1->Max = 100;
break;
case psFileReading:
ProgressBar1->Position = PercentDone;
break;
case psFileReadEnding:
ProgressBar1->Position = 0;
break;
}
ProgressBar1->Update();
}
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|