<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Michael,<br>
do you plan do something else with this "OnValidate" problem ?<br>
Thanks<br>
-Laco.<br>
<br>
<blockquote cite="mid:4DA550DF.6070505@zoznam.sk" type="cite">Hi, <br>
here are diffs with changes, I hope they will be good for all TDataSet
descendants (those specific to FPC and also those which are also for
use in Delphi) <br>
Code which is general (and is used repeatedly) is placed in TField
methods and only small code remains which must be placed into each
TDataSet descendant. <br>
(I patched only TBufDataSet, but later can be updated also other
TDataSet descendants ... remove redundant code and add
Field.Validate(...)) <br>
Thanks <br>
-Laco. <br>
<br>
<blockquote type="cite"><br>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">The whole code, which is repeated (and
can be put in one place) is: <br>
<br>
if not (State in [dsEdit, dsInsert, dsFilter, dsCalcFields]) then <br>
begin <br>
DatabaseErrorFmt(SNotEditing,[Name],self); <br>
exit; <br>
end; <br>
if (Field.FieldNo>0) and not (State in [dsSetKey, dsFilter]) then <br>
begin <br>
if Read
OnlythenDatabaseErrorFmtSReadOnlyField,[Field.DisplayName], <br>
Self); <br>
Field.Validate(Buffer); <br>
end; <br>
</blockquote>
<br>
You are right in your dislike. <br>
<br>
I will create a 'BeforeSetFieldData' in TDataset and put the code in
there, <br>
and the same for 'AfterSetFieldData' with the OnChange code. <br>
<br>
</blockquote>
OK, <br>
Then please do not forget commit necessary changes also in other
descendants (not only in TCustomBufDataSet but also in TParadox,
TMemDataset, TFixedFormatDataSet, TDbf) to completelly fix 'missing
onvalidate call' problem. <br>
Thanks <br>
<br>
</blockquote>
I am still thinking about this. <br>
I have other solution, which is relative simple , puts base logic into
base TField methods (so all TDataSet descendants can benefit from it)
and does not negatively affect existing TDataSet descendants and does
not require introduce new methods (BeforeSetFieldData,
AfterSetFieldData). <br>
Let's distributes repeating used code as follows: <br>
<br>
1. base checks "before" into procedure TField.SetData(Buffer: Pointer;
NativeFormat : Boolean); <br>
<br>
820 begin <br>
821 If Not Assigned(FDataset) then <br>
822 DatabaseErrorFmt(SNoDataset,[FieldName]); <br>
<br>
if not (State in [dsEdit, dsInsert, dsFilter, dsCalcFields])
then //here should be IMO also dsNewValue <br>
DatabaseErrorFmt(SNotEditing,[FDataSet.Name],FDataSet); <br>
<br>
if ReadOnly and (FieldNo>0) and not (FDataSet.State in
[dsSetKey, dsFilter]) then <br>
DatabaseErrorFmt(SReadOnlyField, [DisplayName], Self); <br>
<br>
829 FDataSet.SetFieldData(Self,Buffer, NativeFormat); <br>
--------------------------------------------------------------------------
<br>
<br>
2. into procedure TField.Validate(Buffer: Pointer); <br>
<br>
892 begin <br>
if FData S et.Statein[dsSetKey,dsFilter]thenExit893If <br>
assigned(OnValidate) Then <br>
<br>
--------------------------------------------------------------------------
<br>
<br>
3. "after call" into procedure TDataSet.SetFieldData(Field: TField;
Buffer: Pointer); <br>
begin <br>
if not (State in [dsCalcFields, dsFilter, dsNewValue]) then <br>
DataEvent(deFieldChange, Ptrint(Field)); <br>
end; <br>
<br>
--------------------------------------------------------------------------
<br>
<br>
And now all what we must do, is put into method SetFieldData in
TDataSet descendants one line: <br>
<br>
Field.Validate(Buffer); <br>
and one line at end: <br>
<br>
inherited; //calls "field change" ... this is done by all TDataSet
descendants in fcl-db as a last thing <br>
<br>
<br>
It is only draft, so some detils may be changed ... ;-) <br>
What do you think ? <br>
<br>
Laco. <br>
<br>
<br>
</blockquote>
<br>
<pre wrap=""><pre wrap=""><pre wrap=""><hr size="4" width="90%">
_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated"
href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext"
href="http://lists.freepascal.org/mailman/listinfo/fpc-devel">http://lists.freepascal.org/mailman/listinfo/fpc-devel</a>
</pre></pre></pre>
</blockquote>
<br>
</body>
</html>