multithreading

Discussions about document viewing.
Post Reply
leiqunni
Posts: 11
Joined: Fri Jan 11, 2008 11:44 am

multithreading

Post by leiqunni » Fri Jan 11, 2008 11:54 am

hi there,

i'm writing code multithreading with C++ Builder 2006 like this.

Code: Select all

// Unit1.h ----------------------------------------------------------
class TImageThread : public TThread
{
public:
	__fastcall TImageThread(void);

private:
	void __fastcall Execute(void);
	void __fastcall load(void);
};

//Unit1.cpp
TImageThread *thread;
//-------------------------------------------------------------------
void __fastcall TImageThread::Load()
{
	int ret = Form1->GdViewer1->DisplayFromFile(L"C:\\0000.jpg");
}
//-------------------------------------------------------------------
__fastcall TCountThread::TImageThread(void) : TThread(true)
{
	FreeOnTerminate = true;
	Resume();
}
//-------------------------------------------------------------------
void __fastcall TCountThread::Execute(void)
{
	Synchronize((TThreadMethod)&Load);
}
//-------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	thread = new TImageThread;
}
//-------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
	thread->Terminate();
}
//-------------------------------------------------------------------
but DisplayFromFile function return only code '13' amd I can not see image. why?
DisplayFromURL return code '0' and I cann see image.

leiqunni
Posts: 11
Joined: Fri Jan 11, 2008 11:44 am

Re: multithreading

Post by leiqunni » Thu Jan 31, 2008 12:13 pm

and also this code is wrong....

Code: Select all

//---------------------------------------------------------------------------
int __fastcall Thread(Pointer Parameter)
{
	Form1->GdViewer1->DisplayFromFile("c:\\test.jpg");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
	unsigned int Run_Thread, Thread_ID;
	Run_Thread = BeginThread(NULL, 0, Thread, this, 0, Thread_ID);
}
is there way to perform multi threading?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: multithreading

Post by Loïc » Fri Feb 01, 2008 12:26 pm

Hi,

Did you tried first your code without multi threading ?

There is no reason that the DisplayFromURL() method works and not the DisplayFromFile().

Regards,

Loïc

dapedley
Posts: 10
Joined: Fri Feb 08, 2008 5:19 pm

Re: multithreading

Post by dapedley » Fri Feb 08, 2008 5:31 pm

Hi ,

I am no expert - I have just within the last hour managed to get the demo version running in BDS2006/C++.
I was stuck with the same message - 13. It turned out that the 'L' prefix to a string apparently does not yield the correct wide character format. WideString("xxx") worked for me (same for both DisplayFromFile and DisplayFromPdfFile).
Try:
int ret = Form1->GdViewer1->DisplayFromFile(WideString("C:\\0000.jpg"));

Good Luck,

David

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest