Replace color in all records fon a DBRichViewEdit

General TRichView support forum. Please post your questions here
Post Reply
Bjoern
Posts: 21
Joined: Tue May 11, 2010 4:05 pm

Replace color in all records fon a DBRichViewEdit

Post by Bjoern »

Hello,

i should replace a text-color with another color in all records for a DBRichViewEdit. The data is stored in RTF-format.

Here http://www.trichview.com/forums/viewtopic.php?t=612 is an example for changing the font-size globally, but i can't get it to work.
If i run my routine, nothing happens, no color change, no error :-(

Here is my code (due to this code should run in an update-routine, i can' t use the existing Table/Datasource/DBRichViewEdit-controls exept of the RVStyle), i copied all properties from the existing controls.

Code: Select all

MyTable := TTable.Create(Self);
MyTable.TableName := MyTableName;
      
MyDataSource :=  TDataSource.Create(Self);
MyDataSource.DataSet := MyTable;

MyDBRichViewEdit := TDBRichViewEdit.Create(Self);
MyDBRichViewEdit.DataField := 'Text';
MyDBRichViewEdit.DataSource := MyDataSource;
MyDBRichViewEdit.ReadOnly := False;
MyDBRichViewEdit.FieldFormat := rvdbRTF;
MyDBRichViewEdit.RTFOptions := [rvrtfSaveStyleSheet, rvrtfDuplicateUnicode, rvrtfSaveEMFAsWMF, rvrtfSaveJpegAsJpeg];
MyDBRichViewEdit.RTFReadProperties.TextStyleMode := rvrsAddIfNeeded;
MyDBRichViewEdit.RTFReadProperties.ParaStyleMode := rvrsAddIfNeeded;
MyDBRichViewEdit.Style := MyForm.RVStyle1;
MyDBRichViewEdit.Visible := False;
MyDBRichViewEdit.Parent := MyForm;

MyTable.Open;
MyTable.First;

Counter := MyTable.RecordCount;
for i := 1 to Counter do
begin
    Mytable.Edit;
    MyDBRichViewEdit.CanChange;
    for j := 0 to MyForm.RVStyle1.TextStyles.Count-1 do
    begin
      if (MyForm.RVStyle1.TextStyles[j].Color =MyOldColor)  then
      begin
        MyForm.RVStyle1.TextStyles[j].Color := MyNewColor
      end;
    end;
    MyDBRichViewEdit.Change;
    MyDBRichViewEdit.Format;
    MyTable.Post;
    MyTable.Next;
end;

MyTable.Close;
MyTable.Free;
MyDataSource.Free;
MyDBRichViewEdit.Free;
Does anybody have an idea where my problem or error is ?

Greetings
Bjoern
Sergey Tkachenko
Site Admin
Posts: 17357
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The code seems to be correct. Can you send me a test project to richviewgmailcom?
Bjoern
Posts: 21
Joined: Tue May 11, 2010 4:05 pm

Post by Bjoern »

Sergey Tkachenko wrote:The code seems to be correct.
Thank you for looking at my code ... so i was able to search my error at other places. And found it, i picked the wrong table :-)
Now the replacing work fine.

Greetings
Bjoern
Post Reply