trichview and olevariant

General TRichView support forum. Please post your questions here
Alvaro
Posts: 17
Joined: Wed Apr 14, 2010 4:01 am

trichview and olevariant

Post by Alvaro »

Good day.
Using the tips found in http://www.trichview.com/forums/viewtop ... ight=email, get email using the component TRichViewEdit and looked great. But this example sends the email client side and I'm adapting to the routine sending is done server side and how I use Delphi XE, the object must be passed as type OleVariant. My question is: how to send the client-side object and how can I read it on the server side (remote)?
Li also the topic that guides http://www.trichview.com/forums/viewtop ... olevariant send as SaveRTFToStream using the RTF TStringStream and receive through Stream.DataString, but server-side I could not turn on the type OleVariant Stream, someone could put an example? Thank you and sorry for language mistakes.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Can you create a simple project demonstrating the problem (encoding and decoding in the same application, with assignment instead of saving)?

Send it to richviewgmailcom.
Alvaro
Posts: 17
Joined: Wed Apr 14, 2010 4:01 am

Post by Alvaro »

Dear Sergey, below is the code of the sending email server side (remote). Note that it is identical to the examples you've cited, but the error occurs in the use of variable OleVariant.
If you find it necessary, I can send you the two routines (client-side and server-side remote). Thank you.


function TDSServerSolERP.EnviaEmail2(const Destinatario, Assunto, Corpo,
Arquivo: string; InsereLogotipo: boolean; Anexos: OleVariant; ComCopia: string; RichViewEdit1: OleVariant): String;
var
FServidorSMTP: TIdSMTP;
FSSLHandlerSMTP: TIdSSLIOHandlerSocketOpenSSL;
FIdMessage: TIdMessage;

procedure BuildEmail;
var
Stream : TMemoryStream;
ws : String;
s : TRVRawByteString;
i : Integer;
txtpart, htmpart, txthtmpart, txthtmlimgpart : TIdText;
imgpart : TIdAttachmentMemory;
begin
// saving text
TxtPart := TIdText.Create( FIdMessage.MessageParts );
Stream := TMemoryStream.Create;

//RichViewEdit1.SaveTextToStreamW('', Stream, 80, False, False); //Original line...

TCustomRichViewEdit(RichViewEdit1).SaveTextToStreamW('', Stream, 80, False, False); This was my attempt to type cast,, but generates the error: E2089 Invalid typecast.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

TRichViewEdit cannot be converted to OleVariant, because Delphi component is not an OLE-compatible type.
Alvaro
Posts: 17
Joined: Wed Apr 14, 2010 4:01 am

Post by Alvaro »

So there is a way to send and read the component remotely? Do you have any suggestions? Thank you.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sending the component? I am afraid no. You need to implement this functionality in another way.
Why do you want to send a component?
Alvaro
Posts: 17
Joined: Wed Apr 14, 2010 4:01 am

Post by Alvaro »

My English is not good, but I tried to explain above: I would concentrate sending email server side. Using your examples, already works on the client side, but I wish all the routines were processed on the server due to performance, but by the way is not possible.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Create your server application using TRichView. I do not know another solution.
Alvaro
Posts: 17
Joined: Wed Apr 14, 2010 4:01 am

Post by Alvaro »

That's what I tried initially Sergey, creating a server application with component TRichView have no problems on the server side, what happens is that the problem goes to the client side because the Delphi XE can not send a component TRichView remotely (and not send other objects like ClientDataSet), so I tried send using a type OleVariant (as I did with the ClientDataSet), but I will not take more your time. I'll try to send him into a blob field through ClientDataSet and read it through ClientDataSet.Data propety. Thank you, have a nice day and congratulations for the great component that helps me so much. Hugs.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You should send data, not code/components.
Alvaro
Posts: 17
Joined: Wed Apr 14, 2010 4:01 am

Post by Alvaro »

Is there any property of the RichView component like ClientDataSet.Data?
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

How to convert document in TRichView to OleVariant and back:

Code: Select all

function RVToVariant(rv: TCustomRichViewEdit): OleVariant;
var Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  rv.SaveRVFToStream(Stream, False);
  Result := VarArrayCreate([0, Stream.Size-1], varByte);
  Move(Stream.Memory^, VarArrayLock(Result)^, Stream.Size);
  VarArrayUnlock(Result);
  Stream.Free;
end;

function VariantToRV(rv: TCustomRichView; v: OleVariant): Boolean;
var Stream: TMemoryStream;
    Size: Integer;
begin
  Result := False;
  if VarArrayDimCount(v)<>1 then
    exit;
  Stream := TMemoryStream.Create;
  Size := VarArrayHighBound(v,1)-VarArrayLowBound(v,1)+1;
  Stream.WriteBuffer(VarArrayLock(v)^, Size);
  VarArrayUnlock(v);
  Stream.Position := 0;
  rv.LoadRVFFromStream(Stream);
  Stream.Free;
  rv.Format;
  Result := True;
end;
Alvaro
Posts: 17
Joined: Wed Apr 14, 2010 4:01 am

Post by Alvaro »

Sergey thank you. That was exactly what I wanted.
A hug.
Alvaro
Posts: 17
Joined: Wed Apr 14, 2010 4:01 am

Post by Alvaro »

Sergei, I eliminated the line "rv.Format;" because it created two errors: 1. - The content sent to the memory was read only when a second email was sent 2. - 'Canvas does not allow drawing'. The error number 2 only occurred when I closed the client application and called it again. So I had to restart the application server to send the email. Somewhat confusing is not it? After several tests I saw that was enough to eliminate the rv.Format line, this problem may be the same as reported DavideCase (http://www.trichview.com/forums/viewtopic.php?t=5479). Searching the internet and read something about Canvas.Lock Canvas.Unlock. I was tested and the system worked with these lines and also without them. What do you think ?

Below like it is:

VariantToRV function (rv: TCustomRichView, v: OleVariant): Boolean;
var Stream: TMemoryStream;
Size: Integer;
begin
Result: = False;
if VarArrayDimCount (v) <> 1 then
exit;
Stream: = TMemoryStream.Create;
Size: VarArrayHighBound = (v 1) VarArrayLowBound (v, 1) +1;
Stream.WriteBuffer (VarArrayLock (v) ^, Size);
VarArrayUnlock (v);
Stream.Position: = 0;
rv.Canvas.Lock;
rv.LoadRVFFromStream (Stream);
Stream.Free;
/ / rv.Format;
rv.Canvas.UnLock;
Result: = True;
end;

Thanks.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Format is necessary only if you want to display this TRichView, call its editing method, or save to RTF (and the document contains tables).

Why the error happens - it depends on the context where this function is called. Format should not be called in a thread, for example.
Post Reply