<< Click to display table of contents >> Example: Inserting controls that can modify themselves in DBRichViewEdit |
This example shows how to work with TEdit inserted in TDBRichViewEdit, if you want to store its text in RVF field.
The problem: when user changes text in TEdit, the dataset is not informed that the document is changed, and these changes are not saved.
In this example, we use DBRichViewEdit1:TDBRichViewEdit placed on Form1.
1) Add in the private section of Form1:
procedure EditChange(Sender: TObject);
Implementation:
procedure TForm1.EditChange(Sender: TObject);
begin
if DBRichViewEdit1.CanChange then
DBRichViewEdit1.Change
else
Beep;
end;
2) When creating a new TEdit, assign its OnChange event:
var Edit: TEdit;
begin
Edit := TEdit.Create(nil);
Edit.OnChange := EditChange;
DBRichViewEdit1.InsertControl('', Edit, rvvaBaseline);
end;
3) You'll need to assign this event to all edits loaded from the database field with RichView documents. Use OnControlAction of DBRichViewEdit:
procedure TForm1.DBRichViewEdit1ControlAction(Sender: TCustomRichView;
ControlAction: TRVControlAction; ItemNo: Integer; var ctrl: TControl);
begin
if (ControlAction=rvcaAfterRVFLoad) and (ctrl is TEdit) then
TEdit(ctrl).OnChange := EditChange;
end;
And of course, do not forget to register TEdit in the initialization section of unit:
initialization
RegisterClasses([TEdit]);