Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to do a Loading animation for Database Open including large Blob Images


This question is answered.


Permlink Replies: 3 - Last Post: Jun 7, 2015 2:25 PM Last Post By: Yilmaz Yoru
Yilmaz Yoru


Posts: 167
Registered: 1/1/03
How to do a Loading animation for Database Open including large Blob Images  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2015 6:12 AM
I have database in FMX form including Full HD blob images, and during the Open() process I want to animate icon, or i can also play a movie like spinning animation or loading bar etc.

I try to put Open() process in to multithreding function but still cant success , is there any easy way to do ? I think i missed something here
I also decide that loading blob object by streaming not takes much time than the Open process cuz it is loaded when it is done.

Here are some part of codes

unsigned long __stdcall ThFunc(void *Arg)
{
DM->images->SQL->Clear();
DM->images->SQL->Add("Select * from images where ID="+imid);
//ShowMessage("Open");
DM->images->Open();
//ShowMessage("Opened");
imagesopened=1;
return 0;
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Form1->FloatAnimation1->Start(); //animation of Image3

imagesopened=0;
hThread = CreateThread(NULL, 0 ,ThFunc, &DataThread,0,&ThreadId);
if(hThread==NULL) { ExitProcess(DataThread); ShowMessage("NULL Thread"); }

do
{
//Sleep(50);
Form1->Image3->Repaint();
}
while(imagesopened==0); // Spin or animate loading image during Open() database process
}

FloatAnimation1->Stop();

--
Best Regards
Dr. Yilmaz Yoru ( Mech.Eng. Post.PhD.MSc.)
esenja Energy and Software Company
Eskisehir, TURKEY

http://www.esenja.com
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: How to do a Loading animation for Database Open including large Blob Images [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2015 12:15 PM   in response to: Yilmaz Yoru in response to: Yilmaz Yoru
El 07/06/2015 a las 15:18, YILMAZ YORU escribió:
I have database in FMX form including Full HD blob images, and during the Open() process I want to animate icon, or i can also play a movie like spinning animation or loading bar etc.

I try to put Open() process in to multithreding function but still cant success , is there any easy way to do ? I think i missed something here
I also decide that loading blob object by streaming not takes much time than the Open process cuz it is loaded when it is done.

Here are some part of codes

unsigned long __stdcall ThFunc(void *Arg)
{
DM->images->SQL->Clear();
DM->images->SQL->Add("Select * from images where ID="+imid);
//ShowMessage("Open");
DM->images->Open();
//ShowMessage("Opened");
imagesopened=1;
return 0;
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Form1->FloatAnimation1->Start(); //animation of Image3

imagesopened=0;
hThread = CreateThread(NULL, 0 ,ThFunc, &DataThread,0,&ThreadId);
if(hThread==NULL) { ExitProcess(DataThread); ShowMessage("NULL Thread"); }

do
{
//Sleep(50);
Form1->Image3->Repaint();
}
while(imagesopened==0); // Spin or animate loading image during Open() database process
}

FloatAnimation1->Stop();

The animation does not works beacause you are blocking the main thread
with the do-while loop

Try this:

class TForm1 : public TForm
{
...
private:
...
    void __fastcall ThreadTerminated(TObject *Sender);
...
public:
    __fastcall TForm1(TComponent* Owner);
...
};

class TMyThread : public TThread
{
private:
protected:
    virtual void __fastcall Execute();
public:
    __fastcall TMyThread(bool CreateSuspended);
};
 
__fastcall TMyThread::TMyThread(bool CreateSuspended)
    : TThread(CreateSuspended)
{
}
 
void __fastcall TMyThread::Execute()
{
    DM->images->SQL->Clear();
    DM->images->SQL->Add("Select * from images where ID="+imid);
    DM->images->Open();
}


void __fastcall TForm1::Button2Click(TObject *Sender)
{
    TMyThread *Thread= new TMyThread(false);
    Thread->OnTerminate= ThreadTerminated;
    Thread->FreeOnTerminate= true;
 
    FloatAnimation1->Start();
}
 
void __fastcall TForm1::ThreadTerminated(TObject *Sender)
{
   FloatAnimation1->Stop();
}
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to do a Loading animation for Database Open including largeBlob Images [Edit]
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2015 2:13 PM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio wrote:

TMyThread *Thread= new TMyThread(false);

You are setting the CreateSuspended parameter to false. That means the thread
will begin running as soon as the constructor exits, and thus it could terminate
before you have assigned the FreeOnTerminate property or OnTerminate event
handler. You need to set the CreateSuspended parameter to true instead,
and then call the thread's Start() method when you are ready for it to run:

TMyThread *Thread = new TMyThread(true);
Thread->OnTerminate = ThreadTerminated;
Thread->FreeOnTerminate = true;
Thread->Start();
FloatAnimation1->Start();


--
Remy Lebeau (TeamB)
Yilmaz Yoru


Posts: 167
Registered: 1/1/03
Re: How to do a Loading animation for Database Open including largeBlob Images [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2015 2:25 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thank you very much Antonio & Remy,

I just copy and paste what u typed :) and it works :)

You awesome :)

Yilmaz
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02