Hi there,

I'm having some real issues with restoring a piece of legacy software at my workplace.

I have an offending line of code that I can't debug.

bFound := tblComp.Locate('CompPhone;Title;AddLine2', VarArrayof([sPhone, sTitle, sAddLine2]), [])

When the script gets to this point sPhone, sTitle and sAddLine2 are correctly populated.

When it gets to this line it throws the above error: Project XXX.exe raised exception class EDBEngineError with message 'Operation Not Applicable'

If anyone has any pointers of why this might be happening or how to go about solving the issue that would be great.

Thanks, Bernie.

Hi Bernie and welcome to DaniWeb :)

That code looks fine, can you move the creation of your variant array outside the function and step into the Locate to see exactly where the error occurs?

VarArray := VarArrayOf([sPhone, sTitle, sAddLine2]);
bFound := tblComp.Locate('CompPhone;Title;AddLine2', VarArray, []); // <- step in here using debugger

Hi there,

Thanks for the response. I broke down the statement and when debugging I get to the same error. However, looking closer I can see that the exception is handled, it's just that I want to know why the exception is being thrown so that I can adapt the program.

//Check if this Company has been added to the Company Table
    try
        VarArray := VarArrayOf([sPhone, sTitle, sAddLine2]);
        bFound := tblComp.Locate('CompPhone;Title;AddLine2', VarArray, []); // <- step in here using debugger
        //bFound := tblComp.Locate('CompPhone;Title;AddLine2', VarArrayof([sPhone, sTitle, sAddLine2]), [])

        except on EDBEngineError do
            bFound := False;
    end; //trying

What DB are you using, what is the class of tblComp and what are the types for the fields you are using in locate and types of the variables (string?) ?
Some possible reasons:
- if sAddLine2 type is BLOB it would explain the error (you cannot locate using blob fields).
- if the datatype of the variables (sPhone, sTitle, sAddLine2) doesn't match the column data types.
- On some databases case of the column name might be significant (CompPhone vs COMPPHONE) even if Delphi doesn't think so.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.