WPCubed Product Support

Paragraph styles are not saved

If you type some text, press ctrl-b and continue typing, the text naturally becomes bold. Now try to save the text and open it again. The style wasn't saved.

If you mark text and "bold" it, it is saved correctly.

It seems that the document needs a tag finishing the bold text (actually it should continue in bold when opened)

#1 ♥ 0
10.1k Views 3 users read 4 min

Are we (the company I work for) the only one experiencing this problem? Many have read this post but none has added comments.
This issue has reached a political state. So ever small it may seem some customers are really bugging us about it. Comments or hot-fixes are welcomed.

#2 ♥ 0
support

Hi,

How do you save the text? Is it saved to a database?

I assume if the code which activates Bold (KeyPress) I suggest to call

WPRichText1.Changing before the CurrAttr.AddStyle is called.

Julian

#3 ♥ 0

Depending on size and situation it may reside as a encrypted file or in a blob-field.

I don't use dataset though. I do this:

var  MemoryStream: TMemoryStream;begin  MemoryStream := TMemoryStream.Create;  try    WPRichText1.SaveToStream(MemoryStream);    MemoryStream.Seek(0,soFromBeginning);    result := aDokumentData.SaveFromStream(MemoryStream);  finally    MemoryStream.Free;  end;

Save from stream determines where to put data

We have discovered that the problem only occurs when creating new documents. We can make 1-n fields bold but when we save it's ignored. When editing the document, adding bold-fields, it saves correctly.

When I tried what you suggested, I found out that I had nowhere to put that code-snippet. We use a TWPToolBar

I'll reuse this post. Found out that my colleague added his parallel piece of code to handle those shortcuts:

if (Key = Integer('B')) and (Shift = [ssctrl]) then
  begin
    WPRichText1.TextCursor.CurrAttribute.ToggleCharstyle(WPSTY_BOLD);
    Key := 0;
  end
  else if (Key = Integer('I')) and (Shift = [ssctrl]) then
  begin
    WPRichText1.TextCursor.CurrAttribute.ToggleCharstyle(WPSTY_ITALIC);
    Key := 0;
  end
  else if (Key = Integer('U')) and (Shift = [ssctrl]) then
  begin
    WPRichText1.TextCursor.CurrAttribute.ToggleCharstyle(WPSTY_UNDERLINE);
    Key := 0;
  end;

I'd better try to remove the redundancy here. Somehow call the button or find a shared TAction somewhere.

I have added .Changing to the OnCharacterAttrChange. I'll go on testing.

#4 ♥ 0

Using the buttons the OnCharacterAttrChange is triggered, whereas the home made piece of code doesn't. The best solution will be that the buttons and shortcuts were same code. I'll go look for that now.

When it is triggered the code is saved. The bold made by the code above wasn't saved whereas button-bold's were.

I cannot find the code that the tool-bar uses. Is there really no way to attach a shortcut to these buttons? So I tried this, which doesn't work.

if Shift = [ssctrl] then
    with Sender as TWPRichText do
    begin
      Changing;
      case chr(Key) of
        'B': begin
               TextCursor.CurrAttribute.ToggleCharstyle(WPSTY_BOLD);
               Key := 0;
             end;
        'I': begin
               TextCursor.CurrAttribute.ToggleCharstyle(WPSTY_ITALIC);
               Key := 0;
             end;
        'U': begin
               TextCursor.CurrAttribute.ToggleCharstyle(WPSTY_UNDERLINE);
               Key := 0;
             end;
      end;
    end;
#5 ♥ 0
support

Hi,

You need to call Changined and ChangedText in the KeyDwon event.

procedure TWPTBXForm.WPRichText1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var v: Integer;
begin
  WPRichText1.Changing;
  if (Key = Integer('B')) and (Shift = [ssctrl]) then
  begin WPRichText1.TextCursor.CurrAttribute.ToggleCharstyle(WPSTY_BOLD);
    Key := 0;
  end
  else if (Key = Integer('I')) and (Shift = [ssctrl]) then
  begin WPRichText1.TextCursor.CurrAttribute.ToggleCharstyle(WPSTY_ITALIC);
    Key := 0;
  end
  else if (Key = Integer('U')) and (Shift = [ssctrl]) then
  begin WPRichText1.TextCursor.CurrAttribute.ToggleCharstyle(WPSTY_UNDERLINE);
    Key := 0;
  end;
  WPRichText1.ChangedText;

end;

This way it should work like the toolbutton.

#6 ♥ 0

Can't find the ChangedText metod.

Is it possible to access the TWPToolbar buttons so that a ctrl-b cheks the bold button? Direct access to these buttons must be the best solution.

#7 ♥ 0

I finally managed to do a fix that added shortcuts to the 3 styles and kept functionality in one place (in the TWPRichText.OnKeyDown).

var
  Num: integer;
  SpeedButton: TWPSpeedButton;
begin
  if Shift = [ssCTRL] then
  begin
    case chr(Key) of
      'B': Num := integer(SelBold) + 1;
      'I': Num := integer(SelItalic) + 1;
      'U': Num := integer(SelUnder) + 1;
      else
        Num := -1;
    end;

    if Num >= 0 then
    begin
      SpeedButton := WPTBFormatering.GetIcon(0,256,Num);
      assert(assigned(SpeedButton));
      SpeedButton.Down := not SpeedButton.Down;
      SpeedButton.Click;
      Key := 0;
    end;
  end;

Thanks for the input.

#8 ♥ 0
This category is archived. No new posts are possible.