Default values after Insert but before Post?

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
DestinyR
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 10.03.2010, 16:59

Default values after Insert but before Post?

Post 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?
DestinyR
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 10.03.2010, 16:59

I have partialy solved this problem by following method

Post 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;
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
Post Reply