Page 1 of 1

TDBRichViewEdit - how to force it to post into the dataset

Posted: Fri Jan 23, 2009 3:05 pm
by Ar4i
If I use some non edit changes e.g. things like SetXXXInfo and such how can Force a TDBRichViewEdit to post its contents into the DB?
e.g. I need to manually add/delete one char to make it post the changes - it works this way, but I want to be able to do some changes and then post it w/o user interaction.
I've tried to

Code: Select all

  
  DoSomeChages(rv.RVData);
  rv.Format;
  rv.Invalidate;
  rv.Change;
but still it won't work post any changes unless I go and do some small modification manually.

Posted: Fri Jan 23, 2009 5:24 pm
by Sergey Tkachenko

Posted: Mon Jan 26, 2009 8:29 am
by Ar4i
To be more specific, this code is attached to the BeforePost event of the query:

Code: Select all

procedure Txxx.qrBeforePost(DataSet: TDataSet);
begin
 
  DoSomeChages(rv.RVData);
  rv.Format;
  rv.Invalidate;
  rv.Change; 

end;
The changes made by the DoSomeChanges method won't be posted... and I need a way to do some changes to the document just BEFORE it saves. The same code works just fine if called from some button or such - so there must be some method to make RichView post those changes made to it's RVData to the dataset immediately. I also tried to put Application.ProcessMessages after rv.Change but it didn't help.

Posted: Tue Jan 27, 2009 5:42 pm
by Sergey Tkachenko
Hmm, I am not sure that you can change data in BeforePost...
This event was designed to perform validity checks, and calling Abort is some data are incorrect.
May be you can make changes before calling Post (if you use TDBNavigator, in its BeforeAction event?)

Posted: Thu Jan 29, 2009 10:38 am
by Ar4i
I always change things during before post event, there is no problem with that. Before post is just an event that would fire before the dataset stores data (e.g. immediately after calling dataset.post).

It just seems that RichView does not want to store the changes made to RVData to the underlying field before some event occurs and I don't seem to find a way to force it to do it.

Let's forget about BeforePost, this code has the same problem:

Code: Select all

procedure TXXXForm.Button1Click(Sender: TObject);;
 var n : integer:
begin

  n := Length(DataSet.FieldByName('RVDOC').AsString);

  DoSomeChages(rv.RVData);
  rv.Format;
  rv.Invalidate;
  rv.Change;

if n =  Length(DataSet.FieldByName('RVDOC').AsString) then
 raise Exception.Create('Contents of the FIELD are still the same!');

end; 

Posted: Thu Jan 29, 2009 2:01 pm
by Sergey Tkachenko
There are two problems in this example
1) You must be sure that DataSet is in editing mode. When you call editing method of TDBRichViewEdit, it activates editing mode automatically. But if you use viewer-style methods, you need to activate it yourself, for example by calling rv.CanChange:

Code: Select all

  if rv.CanChange then begin
    <make changes here>
    rv.Change;
    rv.Format;
  end;
2) The code above modifies data in the control and informs DataSet that it was modified. But data are not saved yet, untill you call Post. So when you retrieve value of the field after modification, you receives the old value. The following code should work:

Code: Select all

procedure TXXXForm.Button1Click(Sender: TObject);; 
 var n : integer: 
begin 

  n := Length(DataSet.FieldByName('RVDOC').AsString); 
  if rv.CanChange then begin
    DoSomeChages(rv.RVData); 
    rv.Change; 
    DataSet.Post;
  end;
  if n =  Length(DataSet.FieldByName('RVDOC').AsString) then 
   raise Exception.Create('Contents of the FIELD are still the same!'); 

end;