Reputation: 114
Project *.exe raised exception class $C0000005 with message
access violation at 0x005d9e17:read of adddress 0x00000008
.
About My program:
In form.formcreate(), do some initializaiton; then start a thread, in which init the columns of a listview:
ListView.Columns.Add.Caption := 'Path';
Just this clause throw the exception. How to debug this problem?
And the program does not throw the exception every time. I run 10 times, only 5 times exceptions threw.
Stack:
:005d7e17 TListColumn.DoChange + $F
:005d7f73 TListColumn.SetCaption + $23
:004ccc74 ThreadProc + $4C
:0040947a ThreadWrapper + $2A
:76cf919f KERNEL32.BaseThreadInitThunk + 0xe
:7732a8cb ntdll.RtlInitializeExceptionChain + 0x84
:7732a8a1 ntdll.RtlInitializeExceptionChain + 0x5a
Upvotes: 0
Views: 516
Reputation: 612954
Almost certainly you are attempting to read a field or call a method on an object reference that is nil
.
Typically you would tackle this by using the debugger to work out which reference is nil
and then you should be able to determine how to resolve the problem.
You should be aware that you must not access VCL components from a thread other than the main thread. My guess is that this in fact is the reason for the access violation.
Use the Synchronize
or Queue
methods of the TThread
class to invoke code on the main thread. However, as a general principle, threads should not be performing UI work. I wonder if you should contemplate a different design.
Upvotes: 1