TBaseDataObject =
Class
Private
/// <summary>
/// backing field number list, will be filled each time data is loaded
/// </summary>
fNumberList: TIntegerList;
/// <summary>
/// backing field for where conditions to get data
/// </summary>
fWhereConditions: TStringList;
/// <summary>
/// backing field for order statements to get data
/// </summary>
fOrderStaments: TStringList;
/// <summary>
/// backing field for dataset for binding in grids
/// </summary>
fDataSet: TCustomClientDataSet;
....
Function TBaseDataObject.GetDataSet: TADODataSet;
Var
lRealDataSet: TADODataSet;
Begin
lRealDataSet := TADODataSet.Create(
Nil);
lRealDataSet.Connection := GetConnection();
lRealDataSet.BeforeOpen := TDataTableOpenEvents.DataTableBeforeOpen;
Result := lRealDataSet;
End;
// -----------------------------------------------------------------------------
Procedure TBaseDataObject.Refresh;
Var
lRealDataSet: TADODataSet;
li: Integer;
workingOnLocalDatabase:
String;
Begin
fDataSet.DisableControls;
// avoiding flicker
lRealDataSet := GetDataSet;
lRealDataSet.CommandText := getSelectStatement;
fDataSet.EmptyDataSet;
fNumberList.Clear;
Try
lRealDataSet.Open;
If lRealDataSet.RecordCount > 0
Then
Begin
lRealDataSet.First;
Repeat
fDataSet.Append;
fNumberList.Add(StrToIntDef(lRealDataSet.FieldByName(fPkName).Value, -1));
for li:=0
to pred(lRealDataSet.FieldCount)
do { Alle Felder kopieren }
begin
fDataSet.FieldByName(lRealDataSet.Fields[li].FieldName).Value := lRealDataSet.Fields[li].Value;
end;
fDataSet.Post;
lRealDataSet.Next;
Until (lRealDataSet.Eof);
End
Else
Logger.Debug('
TBaseDataObject.Refresh', '
No data for table %s [%s]', [fTableName, getSelectStatement]);
Except
On E:
Exception Do
Logger.Fatal('
TBaseDataObject.Refresh', '
Could not get field definitions for table %s, Field %S Exeption: %s', [fTableName, lRealDataSet.Fields[li].FieldName, E.
Message]);
End;
fDataSet.First;
DataBase.FreeDataSet(lRealDataSet);
fActive := true;
fDataSet.EnableControls;
End;