Mega Code Archive

 
Categories / Delphi / ADO Database
 

How do i do a locate on a non-indexed field

Question: How do I do a locate on a non-indexed field? Answer: The following function can be added to your to your unit and called as follows: bool __fastcall Locate(const TTable *oTable, const TField *oField, const Char* SvALUE); Table1 is your table component, Table1LName is TField you've added with the fields editor (double click on the table component) and 'Beman' is the name you want to find. // Locate will find SValue in a non-indexed table bool __fastcall Locate(const TTable *oTable, const TField *oField, const Char* SvALUE) { TBookMark bmPos; bool Locate, bFound; Locate = false; bFound = false; if (!oTable->Active) return; if (oTable->FieldDefs->IndexOf(oField->FieldName) < 0) return; bmPos = oTable->GetBookMark; oTable->DisableControls; oTable->First; while(!oTable->EOF) { if(oField->AsString == sValue) { Locate = true; bFound = true; break; } else oTable->Next; } if (!bFound) oTable->GotoBookMark(bmPos); oTable->FreeBookMark(bmPos); oTable->EnableControls; }