Solved

Can't use TComponent in thread object?

Posted on 2006-11-22
4
304 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
ID: 18000455
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
ID: 18000844
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
ID: 18001023
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
ID: 18001166
I see my problem.  I should done this:


     thread := TProgressThread.Create(true);
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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