Struggling to get RTF data into RVE component

General TRichView support forum. Please post your questions here
Post Reply
BennieC
Posts: 28
Joined: Sat Jun 18, 2011 7:00 pm

Struggling to get RTF data into RVE component

Post by BennieC »

Hi, I have data originally saved as RTF into an interbase database. However, when I read it out I can convert it into another RichEdit component but fail to put it into a Richview component.

First I retrieved the data into a file as follows:

Code: Select all


GetaMemoBlob(self, mySpecies.ASubSpc.CurrSubFamily, mySpecies.ASubSpc.CurrSubSpeciesID,
                       aMemotype, myFile, IsValid);


procedure GetaMemoBlob(AOwner: TComponent; SubFamily : string; SubSpeciesID : integer;
                    theMemoType : string; ThePath : string; var MemoValid : boolean);
var
  myQry: TSQLQuery;
  TempField: TBlobField;
begin
  if assigned(SpeciesDBCnx) then
  begin
    try
      myQry := TSQLQuery.create(nil);
      myQry.SQLConnection := SpeciesDBCnx;
      myQry.SQL.Clear;
      myQry.SQL.Add('SELECT * FROM MEMOS WHERE SUBSPECIES_ID = '
            + '''' + inttostr(SubSpeciesID) + '''' +
            ' AND MEMOTYPE=' + '''' + theMemoType + '''');
      myQry.open;
      if not myQry.Eof then
      begin
        MemoValid := true;
        TempField := TBlobField(myQry.FieldByName('MEMODATA'));
        TempField.SaveToFile(ThePath);
      end
      else
        MemoValid := false;
      myQry.close;
    finally
      FreeAndNil(myQry);
    end;
  end;
end;
I then put it into a RVE Component without success as follows:

Code: Select all

    
    if IsValid then
    begin
      aRVComponent.LoadRVF(myFile);
      aRVComponent.Format;
    end;
Putting it into a RichEdit field however works fine

Code: Select all

    if IsValid then
    begin
      aREComponent.Lines.LoadFromFile(myFile);
    end;
Could you please tell me what I am doing wrong
Bennie
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Code: Select all

      aRVComponent.Clear;
      aRVComponent.LoadR[color=red]T[/color]F(myFile); 
      aRVComponent.Format;
BennieC
Posts: 28
Joined: Sat Jun 18, 2011 7:00 pm

Still struggling

Post by BennieC »

I have converted my original RTE data into RVE format and then saved it into an interbase db (All data is being transferred to a new program and data). The code to do this was

Code: Select all

              with GenSQLQry do
              begin
                SQL.Clear;
                SQL.Add('UPDATE MEMOS SET MEMODATA = :MEMO' +
                  ' WHERE SUBSPECIES_ID = ' + '''' + inttostr(SubSpeciesID) + '''' +
                  ' AND MEMOTYPE = ' + '''' + MemoType + '''');

//             RTE to RVE Conversion
                Stream := TMemoryStream.Create;
                aRTEField := TRichEdit.Create(AOwner);
                aRVEObject := TCustomRichViewEdit.Create(AOwner);
                TBlobField(imgtable.FieldByName('Memo' + inttostr(i))).SavetoStream(Stream);
                Stream.Position := 0;
                aRVEObject.LoadRTFFromStream(Stream);
                Stream.Position := 0;
                aRVEObject.SaveRVFToStream(Stream,false);

                Params[0].LoadFromStream(Stream,ftBlob);
                Stream.Free;
                aRTEField.Free;
                aRVEObject.Free;

                try
                  GenSQLQry.ExecSQL;
                except
                  on E: Exception do
                    MessageDlg('DataInsert Error (SubSpecies - Memos)',
                      mtWarning, [mbOK], 0);
                end;
              end;
However, now that I am reading it out in the new system, into a RVedit component, I get nothing if I use LoadRVE and sometimes partial data when I use loadRTF as shown in the code before.
Why did the original conversion not work and for some reason it apears that it stayed in RTE format. And why does load RVF not work and loadRTF only partially
Regards
Bennie
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I never worked with SQL queries seriously, so I cannot tell if this code correct or no, but there are some problems.

1) Use Stream.Clear instead of Stream.Position := 0. Otherwise, RVF will be written over RTF, so it may be RVF at the beginning followed by a part of RTF - i.e. corrupted data.

2) You do not assign Style to aRVEObject. Create TRVStyle component and assign its to aRVEObject.Style

3) Some properties must be assigned to load RTF and save RVF in the best way.
aRVEObject.RTFReadProperties.TextStyleMode := rvrsAddIfNeeded;
aRVEObject.RTFReadProperties.ParaStyleMode := rvrsAddIfNeeded;
aRVEObject.Options := aRVEObject.Options + [rvoTagsArePChars];
aRVEObject.RVFOptions := aRVEObject.RVFOptions + [rvfoSaveTextStyles, rvfoSaveParaStyles].
If you have hyperlinks in RTF, you also need to process OnReadHyperlink event.
Post Reply