Page 1 of 1

Default values after Insert but before Post?

Posted: 06.04.2010, 10:14
by DestinyR
Hi!
Whether developers can to give instruction how to see default values in Tdbgrid after the operation of Insert, but to the operation of Post. I.e. I want to offer to the user to enter already the partly filled record in a table?

I have partialy solved this problem by following method

Posted: 08.04.2010, 15:24
by DestinyR
Add ROQuery for select default falues and realize next procedure which called in AfterInsert event:

Code: Select all

procedure TForm1.FillDefaultValues(ds: TDataSet);
var
  strSQLDefValues: String;
  i: Integer;
  DefValue: String;
begin
  if not (ds is TZAbstractRODataset) then exit;
  if ds.State <> dsInsert then exit;

  qrDefValues.Close;
  strSQLDefValues := '';
  for i := 1 to TZAbstractRODataset(ds).DbcResultSet.GetMetadata.GetColumnCount do
  begin
    if TZAbstractRODataset(ds).DbcResultSet.GetMetadata.HasDefaultValue(i) then
      DefValue := TZAbstractRODataset(ds).DbcResultSet.GetMetadata.GetDefaultValue(i)
    else
      DefValue := '''''';

    if strSQLDefValues <> '' then
      strSQLDefValues := strSQLDefValues + ',' + DefValue
    else
      strSQLDefValues := DefValue;
  end;
  strSQLDefValues := 'select ' + strSQLDefValues;

  try
    qrDefValues.SQL.Text := strSQLDefValues;
    qrDefValues.Open;
    for i := 1 to TZAbstractRODataset(ds).DbcResultSet.GetMetadata.GetColumnCount do
    begin
      if TZAbstractRODataset(ds).DbcResultSet.GetMetadata.HasDefaultValue(i) then
        ds.Fields[i-1].AsVariant := qrDefValues.Fields[i-1].AsVariant;
    end;
  except
    on E: Exception do
    begin
      MessageDlg('Unable to set default values:' + #13#10 +
        E.Message, mtError, [mbOk], 0);
    end;
  end;
end;

Posted: 13.04.2010, 23:57
by mdaems
DestinyR,

The developers are gone since long. The maintainer(s?) don't know a solution working out of the box.

When you want to show the database defaults you might be able to find them in the metadata structures zeoslib uses internally. Not sure if there's a way to acces them through the layered zeoslib structure, however.

In zeoslib 7 there's also a new feature 'support for DefaultExpression TField property' introduced by SVN rev 517

Mark