Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-12

Dataset indexdefs.find: documentation wrong?

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers
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?

Thanks,
Reinier

Reply by email

Michael Van Canneyt
to Reinier Olislagers
Reinier Olislagers wrote 21 lines
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.

Reply by email

LacaK
to Reinier Olislagers: With this code: procedure SortBufDataSet(DataSet: TBufDataSet; const FieldName: string);…

Reinier Olislagers wrote / napísal(a):

Show quoted text 23 lines
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?

Delphi documentation says, that exception is raised http://docwiki.embarcadero.com/Libraries/XE2/en/Data.DB.TIndexDefs.Find

May be, that IndexOf can be used to find index without raising exception. -Laco.

Reply by email