Solved

Can't use TComponent in thread object?

Posted on 2006-11-22
4
297 Views
Last Modified: 2010-04-05
I've added a Thread Object named TProgressThread to my Delphi7 Win32 project.  I created this method in the unit:

procedure TProgressThread.GetRemoteFile;
begin
     FtpClient1 := TFtpClient.Create(Self);
...
end;

I get this error when compiling:

[Error] ProgressThread.pas(72): Incompatible types: 'TComponent' and
'TProgressThread'

Line 72 is the FtpClient1 line above.   I'm trying to put the downloading of a file on its own thread.  Why can't I use the FtpClient1 object in the thread class?

Thanks,
Brett

0
Comment
Question by:brettr
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 125 total points
Comment Utility
No one says you can't... you just can't pass the thread as the owner. Try passing nil instead.

Regards,
Russell
0
 

Author Comment

by:brettr
Comment Utility
That does compile but when I create the thread in another unit as

thread.Create(true);

I get this error after running the above line:

Debugger Exception Notification
Project myapp.exe raised exception class EAccessViolation with message 'Access' violation at address 00403B6A in module 'myapp.exe'.  Read of address 8BD88B4F'.  Process stopped.  Use Step or Run to continue.

Do you have any suggestions for that?

Thanks,
Brett
0
 
LVL 11

Expert Comment

by:robert_marquardt
Comment Utility
Is TFtpClient a VCL component or uses a VCL component, ie does it display anything?
The VCL is not threadsafe so it may not be usable in a thread.
0
 

Author Comment

by:brettr
Comment Utility
I see my problem.  I should done this:


     thread := TProgressThread.Create(true);
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now