Text Color not chaging, TextObject.Insert and others

  • Hello again

    Thanks for your previous reply.

    I have 4 questions this time, which I cannot find an answer for.
    Thanks in advance for any possible reply.

    1- I want to add text in several different colors. I'm using the following code without result. Any help appreciated:

    CurrAttr.AddStyle([afsBold]);
    CurrAttr.fontname:='Courier New';
    CurrAttr.color:=clred;
    Currattr.size:=10;
    InputString('My Text');

    The text is written in red.

    2- About the TStream fileextension changing to BMP. Where can I change that?

    3- I want the component to bbe read-only The problem is that when I set it to read only it doesn't allow me to add images in the format:
    "WPRichText1.TextObjects.Insert(obj);"

    4- How can I add an hyperlink to the text so, when it is clicked, another window is opened inside the program? (the window to be opened depends on the text clicked).

    Thanks. Andre

  • Hi,

    1)
    <i>CurrAttr.color:=clred; </i> does not work - Please use CurrAttr.Color := CurrAttr.ColorToNr( clRed, true);

    2) About the TStream fileextension changing to BMP. Where can I change that?

    fileextension is a variable of the TWPObject class.

    3) ... well - you need to toggle property ReadOnly to insert the object.

    4) Add a hyperlink and use the event 'HyperlinkEvent' - you need to use ShowModal for the other form.

  • About #3 in the previous message, I still cannot add the bitmap to the wprichtext: I have the image in a tbitmap and want to draw it. What's wrong with the below code?

    bmpstream:=tmemorystream.create;
    bmp2.savetostream(bmpstream);
    bmp2.free;
    obj:=TWPObject.create(mainform.WPRichText1); //use TWPOImage
    bmpstream.position := 0; // Inserted
    obj.loadfromstream(bmpstream);
    obj.fileextension:='BMP'; //Not here, BEFORE LoadFromStream
    WPRichText1.readonly:=false;
    WPRichText1.TextObjects.Insert(obj);

    Nothing happens...any clues?
    Thanks alot again for the previous help.

  • Julian

    Still no luck, but we are almost there.
    With the below code it writes the image but always with the same (small) size. How can I change the size of the image being written? No matter what the size of the bmp is, it always paints it very small...

    Any help appreciated.

    procedure TForm1.Button1Click(Sender: TObject);
    var obj : TWPOImage;
    bmp:tbitmap;
    begin
    with wprichtext1 do begin
    bmp:=tbitmap.create;
    bmp.loadfromfile('d:\d.bmp');
    obj:=TWPOImage.create(wpRichText1);
    obj.fileextension:='BMP';
    obj.assign(bmp);
    wpRichText1.TextObjects.Insert(obj);
    end;
    end;

  • Zitat von jziersch

    Hi,


    Hello,

    wouldn't it be a good idea to encapsulate the "ColorToNr" in the setter method of "CurrAttr.Color" so that the calling code only has to do a "CurrAttr.Color := clRed"?

    Maybe the property "Color" could call "ColorToNr(..., false)" and a new property "NewColor" could call "ColorToNr(..., true)"?

    Just an idea...

    Ciao,
    Ralf

    • Offizieller Beitrag
    Zitat

    wouldn't it be a good idea to encapsulate the "ColorToNr" in the setter method of "CurrAttr.Color"

    ... sounds like a good idea but I prefer to leave it as it is since all the Attr.Color, ParColor etc work the same way and it is not possible to add a setter for CPAttr^.Color for example. So it stays consistent if I leave it like it is.

    So please use
    CurrAttr.ColorToNr( TColorValue, true )
    when ever you need a color value.

    • Offizieller Beitrag

    I did not forget you (sent you privat message, too) - The code I posted was tested, I mean this one:

    Code
    bmpstream:=tmemorystream.create;Image1.Picture.Bitmap.savetostream(bmpstream);obj:=TWPOImage.create(WPRichText1);obj.fileextension:='BMP';  // 1.bmpstream.Position := 0;obj.loadfromstream(bmpstream); //2.WPRichText1.readonly:=false; WPRichText1.TextObjects.Insert(obj);

    And this will also work:

    Code
    obj:=TWPOImage.create(WPRichText1);
    obj.loadfromfile('c:\4.bmp');
    WPRichText1.readonly:=false; 
    WPRichText1.TextObjects.Insert(obj);

    But obj.Assign(bitmap) does not - you will need to assign it to obj.Picture.Graphic if you need that functionality.

    Julian

  • Julian,

    Thanks again for your help.

    Unfortunately only the second code you sent me (the one that does the obj.loadfromfile) works. Anyway I need to load the bmp from memory and not from a file.

    The first code (that uses obj.loadfromstream) writes the bitmap in a very small size (being the bmp a big or small picture, the size it is written is always the same).

    The last code (obj.Picture.Graphic.assign) gives an error.
    Anyway correcting that error with a "obj.picture.graphic:=tbitmap.create", works, but the picture is again written with a default small size.

    Any help highly appreciated.

    PS: Try this code and see for yourself the problem of drawing a small image:

    procedure TForm1.Button1Click(Sender: TObject);
    var obj : TWPOImage;
    bmp:tbitmap;
    begin
    bmp:=tbitmap.create;
    bmp.loadfromfile('d:\a.bmp');
    obj:=TWPOImage.create(WPRichText1);
    obj.fileextension:='BMP';
    obj.picture.graphic:=tbitmap.create;
    obj.picture.graphic.assign(bmp);
    WPRichText1.readonly:=false;
    WPRichText1.TextObjects.Insert(obj);
    bmp.free;
    end;