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…
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?
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 …
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
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]