Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

RichEdit property inspector edit - SetObjectValue causes Delphi line insertion error or nulls

I've derived a class from TLMDStringsPropEditor to allow me to override the Edit function so I can edit a RichEdit field.
But on calling SetObjectValue I get a Delphi exception 'RichEdit line insertion error'.

If I just do a simple Get and Set (with no editing) the richtext value is removed:

void __fastcall TnRichEditPropEditor::Edit()
{
    try
    {
        TStrings * psl = (TStrings *)(GetObjectValue(0));
        if(!psl)
            throw Exception(String(__FUNC__)+String().sprintf(" !psl"));

        SetObjectValue(psl);
    }
    catch(Exception & e)
    {
        LOGEXCP(e);
    }
}



The exception is thrown from ComCtrls.pas: TRichEditStrings.Insert  line 11558:
    if RichEdit.SelStart <> (Selection.cpMax + Length(Str)) then
      raise EOutOfResources.Create(sRichEditInsertError);



Question: what is the correct way to provide a RichEdit property editor?
Tagged:

Comments

  • 1 Comment sorted by Votes Date Added
  • The solution was to set the RichEdit via a memory stream:


            TStrings * psl = (TStrings *)(GetObjectValue(0));
            if(!psl)
                throw Exception(String(__FUNC__)+String().sprintf(" !psl"));

            //create a richtexteditor dialog here
            pDlg->RTFText = psl;

            if(!pDlg->Execute())
                return;

            std::auto_ptr<TMemoryStream> psm(new TMemoryStream);
            pDlg->RTFText->SaveToStream(psm.get());
            psm->Seek(0,soFromBeginning);

            psl->LoadFromStream(psm.get());

Sign In or Register to comment.