开发者

Why DefaultExpression property work only with BDE?

How can I use DefaultExpression property for TField with MS Access or SQL Server, it seems to work onl开发者_运维问答y with BDE.


Not an exact answer, but it is a workaround. I just call something like the next routine from the AfterInsert event handler of the dataset:

procedure Flds_SetToDefExpr(const AFlds: array of TField);
var
  i : Integer;
begin
  for i := Low(AFlds) to High(AFlds) do
    with AFlds[i] do begin
      DataSet.Edit;
      if ( DefaultExpression='' ) then
        Clear
      else if HasOuterQuotes(DefaultExpression) then
        Value := RemoveOuterQuotes( DefaultExpression,True,False )
      else
        Value := StrToInt(DefaultExpression); //raises if not an integer!
    end;
end;

Ofcourse you could change this routine to accept a TDataSet, which loops it's fields and does the same to all fields.


I think that DefaultExpression property dosn't work with ADO, but we get workaround using TBetterADODataSet by Vassil Nazarov that use something like:

Procedure TBetterADODataSet.DoOnNewRecord;
  Var i: Integer;
Begin
  FModifiedFields.Clear;
  For i:=0 To Pred(Fields.Count) Do With Fields[i] Do
    If DefaultExpression<>'' Then Try
      AsString:=DefaultExpression;
    Except
      On E: Exception Do
        ShowMessage(E.Message);
      End;
  Inherited DoOnNewRecord;
End;

You can get it for free here: TBetterADODataSet

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜