Board index » delphi » Program crash on TTable.FindKey

Program crash on TTable.FindKey

Quote
Kamran Behbahani wrote:

> Dear all,
>     For some time I have had problems when I execute a TTable.FindKey
> method. In some cases it gives me an access violation error or simply
> crashes the program. Today I realized the problem seems to happen when the
> record pointer is already located on the very record that the FindKey method
> is to search for.

> Is this a bug? Is this a corrupted index file? Is there a solution other
> than using the locate method which may be slower?

No, no, Kamran .. trust me, if it's an "access violation error" then
it's a bug in your program somewhere (and you're lucky that the pointer
is turning out to be bad so that you -get- an "access violation").  It's
not a bug in findKey.  I'm not sure what it -is- but ... don't waste
time pursuing it as a bug in Delphi or FindKey.  :-/  

All I can do about the immediate problem you're facing is, "programmer
to programmer, been-there-done-that-although-we're-half-a-world-away"
... is sympathize.  ;-)  You're not the first human being who hammered
his head against the wall on such a problem.  :-}

 

Re:Program crash on TTable.FindKey


Dear all,
    For some time I have had problems when I execute a TTable.FindKey
method. In some cases it gives me an access violation error or simply
crashes the program. Today I realized the problem seems to happen when the
record pointer is already located on the very record that the FindKey method
is to search for.

Is this a bug? Is this a corrupted index file? Is there a solution other
than using the locate method which may be slower?

Thanks

Kamran

Re:Program crash on TTable.FindKey


Quote
Kamran Behbahani (kam...@student.unsw.edu.au) wrote:

: Dear all,
:     For some time I have had problems when I execute a TTable.FindKey
: method. In some cases it gives me an access violation error or simply
: crashes the program. Today I realized the problem seems to happen when the
: record pointer is already located on the very record that the FindKey method
: is to search for.

: Is this a bug? Is this a corrupted index file? Is there a solution other
: than using the locate method which may be slower?

What version of Delphi?  What version of BDE?  What operating
system?  What kind of tables?  What kind of index?

Have you checked whether it helps to put the FindKey
statement inside a try...except loop?
--
Rick Carter
carte...@email.uc.edu

Re:Program crash on TTable.FindKey


Hi again,
    In respond to Richard let me say that I am currently using D5 on Win98
with the BDE that ships with it, But the FindKey problem used to happen
before when I used D4 as well. The tables are ttFoxpro type tables with .cdx
indexes created programatically by the program itself.

I have had my fair share of access violation errors to have learnt a lesson
or two. The strange thing about this error is that I have had it many times
during the past year, but every time on a line calling the FindKey function.

Previously I discovered that the problem can arise from a corrupted index,
ie I would get the error, use DBD to regenerate the index, run the program
again and find that it now works just fine.

But in the latest episode the FindKey is called twice within the same
procedure. Both calls search for the same record. The first search finds the
record ok, some processing is done (which might change the record pointer
but in this case it does not) then the second search is carried out for the
same record. But this time it fails.

What is more, using Locate instead of FindKey manages to solve the problem
every single time. As a result I have found that Locate is replacing all my
FindKey calls one by one as I go on developing!

Thank you all for your responses.

Regards
Kamran

Other Threads