TDADataTableRules OnBeforePost problem

hi,
in the OnBeforePost event of a TDADataTableRules derived class i’m trying to change to value of a TBlobField
in our D7 + old DA version this simply works using this code:

procedure TInfoDataTableRule.BeforePost(Sender: TDADataTable);
var
ss:TStringStream;
s:string;
begin
ss:=TStringStream.Create(’’);
ss.CopyFrom(fld_Blob.Stream,fld_Blob.Size); // fld_Blob is IUROStream
s:=ss.DataString;
// do some stuff with s
ss.Seek(0,soBeginning);
ss.WriteString(s);
ss.Seek(0,soBeginning);
DataTable.Fields[idx_fld_Blob].LoadFromStream(ss);
end;

now in the current version the stream is empty, so i must be using it the wrong way i guess?
so the question is how to get a hold of the content of the blob field in the BeforePost event…

tia!
Marc

what version of Delphi was used with current DA 9.x version? D7?

in modern versions of delphi, I can recommend to read TBytes, transform them into string, do some stuff, transform to TBytes back and write TBytes to stream.

on what line stream is empty? at the beginning of code of after writing data back to stream?

done in D10.2 (tokyo)

ss.CopyFrom(fld_Blob.Stream,fld_Blob.Size);

fld_blob.size = 0, so right at the beginning
but even if i do
self.dataset.fieldbyname(‘fld_blob’).asstring it returns an empty string

now this comes from a TDbRichEdit, and that one does persist it’s data (tracing into the vcl)

if i run the same code in the AfterPost event, the data is there, so i guess the wrong buffer is returned…?

tia,
marc

can you create a simple testcase with it, pls? I’ll behavior.
you can attach it here or drop email to support@

will try with TDAClientDatasets in memory
don’t have northwind or so installed…

I can recommend to use TDAMemDataTable

have the same problem on another datable for which i want to check the contents of a memofield in the beforepost, the new value isn’t available either…

but this is due to an oncalcfield ‘field’ which i use to hold the original value, it appears that the oncalc event is now fired continiously which is different from the old DA version …

what is the best way to get a hold of the old field value inside the dadatatablerules?

in DataTableRules, you have access to own table (DataTable).
if you cast it to IDARowHelper and call IDARowHelper.GetPreviousValues you can get old value of field.
it can be something like:

oldvalue := (DataTable as IDARowHelper).GetPreviousValues('myname'); //name

or

oldvalue := (DataTable as IDARowHelper).GetPreviousValues(1); //index

also, I can recommend to look at the Business Rules Scripting article .

hi Evgeny,

i used
DataTable.FieldByName(fld_WeegProtocolvdm_Informatie).OldValue
which works
or shouldn’t i use the oldvalue prop?

if it works for you, you shouldn’t change it.

it just another workaround for getting value.
old value is stored also at TDADeltaChange level.
GetPreviousValues method gets old value via calling Delta.GetDelta.CurrentChange(Self).OldValueByName[lFld]