WPCubed Product Support

FastAppendText dosen't copy graphics

Hi! I have a text saved by wptools. In that text, there is a special tag, wich must be replaced by an image (User signagture).

The code I'm using:

procedure GeraAssinatura(var wpEditor: TWPRichText; CodigoUsuario, TagImagem: String);
var Image1: TImage;
    BlobStream: TStream;
    JPEGImage: TJPEGImage;
    TextObject: TWPOImage;
begin
   Image1 := TImage.Create(Image1);
   with dmana do
   begin
      q_assinatura.Close;
      q_assinatura.DataSet.Params[0].Value := w_empresa;
      q_assinatura.DataSet.Params[1].Value := w_estab;
      q_assinatura.DataSet.Params[2].Value := CodigoUsuario;
      q_assinatura.Open;
      if q_assinaturaASSINATURA_USUARIO.BlobSize <> 0 then
      begin
         BlobStream := q_assinatura.CreateBlobStream(q_assinaturaASSINATURA_USUARIO, bmRead);
         JPEGImage  := TJPEGImage.Create;
         try
            JPEGImage.LoadFromStream(BlobStream);
            Image1.Picture.Assign(JPEGImage);
         finally
            BlobStream.Free;
            JPEGImage.Free;
         end;
      end
      else Image1.Picture := nil;
   end;

   wpEditor.Finder.ToStart;
   while wpEditor.Finder.Next(TagImagem) do
   begin
      wpEditor.CPPosition       := wpEditor.Finder.FoundPosition;
      wpEditor.Finder.FoundText := '';
      wpEditor.TextObjects.InsertCopy(Image1.Picture.Graphic);
   end;
   wpEditor.DelayedReformat;
end;

When I run the program, it works great! The wprich passed to that procedure shows the image perfectlly. But, when I use FastAppendText, or CopyToClipboard and PasteFromClipboard, to copy that text to the end of another wprich object, the image is not copied!

I'm doing something wrong?? Help me!!

Thanks

#1 ♥ 0
6.4k Views 2 users read 2 min
support

Hi,

Instead of
wpEditor.TextObjects.InsertCopy(Image1.Picture.Graphic);

you should do this:

TextObject := nil; // at the start

then load the graphic from DB

TextObject.FileExtension := 'JPG';
TextObject.LoadFromStream(BlobStream)

the insert that image using you Finder.Next loop

wpEditor.TextObjects.Insert( TextObject )

Do not free that TextObject unless it has not been inserted!

#2 ♥ 0

Julian, I tried some code using your hints. But, I'm getting an "Accsses Violation" when I call

TextObject.FileExtension := 'JPG';

Tried to create the TextObject variable before it, but don't know how to do this.

Can you help me?

Thanks

#3 ♥ 0

Hey guys, any ideas?? I'm lost here!!!

Thanks

#4 ♥ 0
support

TextObject is defined but not created in your code.

TextObject := TWPOImage.Create(wpEditor);
TextObject.FileExt := 'JPG';
TextObject.LoadFromStream(...)

now you can insert that TextObject using

wpEditor.Finder.ToStart;
didInsert := FALSE;
while wpEditor.Finder.Next(TagImagem) do
begin
wpEditor.CPPosition := wpEditor.Finder.FoundPosition;
wpEditor.Finder.FoundText := '';
wpEditor.TextObjects.Insert(TextObject);
didInsert := TRUE;
end;

if not didInsert then TextObject.Free;

Julian

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