Need convert to ANSI !

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
editorman
Posts: 2
Joined: Tue Feb 01, 2011 10:07 am

Need convert to ANSI !

Post by editorman »

Hi !
I made an application, a text editor which uses SRichViewEdit component ( v3.2), with RTFReadProperties.UnicodeMode = rvruNoUnicode.
Database connection: Firebird 2.1, ADO, IBProvider3 with unicode_mode = false. Charset of FB database is WIN1250.

I make a document with this text :"Hello World ! ", i save them into database, ( or i edit later the text). INSERT and UPDATE works both correct.
When i edit this document style ( font size set to 30 etc.) and save RVF into database, comes up an error:
"IB-native IN-parameter value create failed. Position 0. Write BLOB: Can't translate text from UNICODE to [WIN1250]"

How can i convert this full document to ANSI ?
Users can edit documents, copy+paste from older documents, etc., that's why i have to convert it first.

I made a converter by this article, but it thid'nt work for me:
http://www.trichview.com/forums/viewtopic.php?t=70

My converter's code:

Code: Select all

procedure ConvertToANSI(rv: TCustomRichView);
var i: Integer;
begin
  ConvertRVToANSI(rv.RVData);
  for i := 0 to rv.Style.TextStyles.Count-1 do
    rv.Style.TextStyles[i].Unicode := False;
end;

procedure ConvertRVToANSI(RVData: TCustomRVData);
var i,r,c, StyleNo: Integer;
    table: TRVTableItemInfo;
begin
  for i := 0 to RVData.ItemCount-1 do begin
    StyleNo := RVData.GetItemStyle(i);
    if StyleNo>=0 then begin
      if RVData.GetRVStyle.TextStyles[StyleNo].Unicode then
     begin
        RVData.SetItemTextA(i, RVData.GetItemText(i));
        RVData.GetItem(i).ItemOptions := RVData.GetItem(i).ItemOptions - [rvioUnicode];
      end;
      end
    else if RVData.GetItemStyle(i)=rvsTable then begin
      table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to table.Rows.Count-1 do
        for c := 0 to table.Rows[r].Count-1 do
          if table.Cells[r,c]<>nil then
            ConvertRVToANSI(table.Cells[r,c].GetRVData);
    end;
  end;
end;
This code never runs, because RVData.GetRVStyle.TextStyles[StyleNo].Unicode is always false:

Code: Select all

        RVData.SetItemTextA(i, RVData.GetItemText(i));
        RVData.GetItem(i).ItemOptions := RVData.GetItem(i).ItemOptions - [rvioUnicode];
When is save the RVF, it still contains unicode....
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I believe the problem is non in ANSI/Unicode, but in a field type: it seems that it requires a plain text and cannot contain binary data, like RVF. It
Is it possible to change a field type?
editorman
Posts: 2
Joined: Tue Feb 01, 2011 10:07 am

Post by editorman »

Yes, you are right. I changed the BLOB's type to 0 and it is working. Very strange, when I save the editor's content in RTF format with sub-type 1, then it works. If I save in RVF format, then it doesn't work. The RVF format only works with sub-type 0 if it contains formatted text.
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

RVF is a binary format, while RTF (with default settings) is a plain text format containing only characters with codes less than 128, so RTF can be stored in memo fields.
Post Reply