[fpc-pascal] Dataset indexdefs.find: documentation wrong?

Michael Van Canneyt michael at freepascal.org
Sun Dec 2 19:13:19 CET 2012



On Sun, 2 Dec 2012, Reinier Olislagers wrote:

> With this code:
> procedure SortBufDataSet(DataSet: TBufDataSet; const FieldName: string);
> var
>  Index_Name: string;
> begin
>  Index_Name := FieldName + '__IdxA';
>  if (DataSet.IndexDefs.Find(Index_Name)<>Nil) then
> ...
> the last line throws an exception if the index does not exist;
> corresponding db.pas code:
> function TIndexDefs.Find(const IndexName: string): TIndexDef;
> begin
>  Result := (inherited Find(IndexName)) as TIndexDef;
>  if (Result=Nil) Then
>    DatabaseErrorFmt(SIndexNotFound, [IndexName], FDataSet);
> end;
>
> However, the documentation states:
> Find...returns Nil if no matching index definition was found.
>
> Not a Delphi guy - should the implementation or the documentation be fixed?

I'll have a look tomorrow. 
Normally, the (unwritten) convention is that 'Find' returns nil. 
'Get' raises an exception.

Michael.



More information about the fpc-pascal mailing list