Delphi Error "Unable to find record. No Key specified" - How to fix

Опубликовано: 15 Октябрь 2024
на канале: Gean Marques
793
9

Learn how to fix the Delphi error "Unable to find record. No Key specified”. This error happens when Delphi is unable to identify the primary key for your DataSet.

The code used in the presentation is:

for i := 0 to MyClientDataSet.Fields.Count - 1 do
begin
field := MyClientDataSet.Fields[ i ];
if i = 0 then
field.ProviderFlags := [ pfInUpdate, pfInWhere, pfInKey ]
else
field.ProviderFlags := [ pfInUpdate ];

fieldCopy := TField.Create( Self );
fieldCopy.ProviderFlags := field.ProviderFlags;
fieldCopy.FieldName := field.FieldName;
MyTSQLDataSet.Fields.Add( fieldCopy );
end;