Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Merging 2 RTF files into a Richedit

969 views
Skip to first unread message

Christer Jansson

unread,
Dec 9, 2001, 2:18:51 AM12/9/01
to
Hi

I have tried to merge 2 RTF files into one RichEdit, even tried to merge 2
RichEdit into a another.

Please help me!

Thanks Christer Jansson


Ralph Friedman

unread,
Dec 9, 2001, 4:07:35 AM12/9/01
to
Christer,

in article <3c131052$1_1@dnews>, you wrote:

> I have tried to merge 2 RTF files into one RichEdit, even tried to merge 2
> RichEdit into a another.
>
> Please help me!
>

after my sig is the source for a component descended from TRichEdit which
allows you to do that (see Append method).

--
Regards
Ralph (TeamB)
==
Use Borland servers; TeamB doesn't see posts via ISPs
http://www.borland.com/newsgroups/genl_faqs.html
==
We do not quit playing because we grow old,
we grow old because we quit playing.
== Source starts here ==
unit GSRichEdit;

{ Copyright (c) 1998 - 1999, Garlin Software Development Corp.,
Middletown, NJ, USA, All rights reserved.

May be freely copied and used for all commercial and
non-commercial purposes, except publishing in any form,
as long as the above copyright statement, the rest of
the text in this comment block and the Copyright
const below are retained.
}

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;

const
copyright = 'Copyright © 1998 - 2001 Garlin Software Development Corp., '
+ 'Middletown, NJ, USA. '
+ 'All Rights Reserved';

type
TGSRichEdit = class(TRichEdit)
protected { Protected declarations }
function FetchText(AFilename: string): integer;
public { Public declarations }
function Append(AFilename: string): integer; virtual;
function Insert(AFilename: string): integer; virtual;
end;

procedure Register;

implementation

uses
RichEdit;

function EditStreamCallback(dwCookie: Longint; pbBuff: PByte;
cb: Longint; var pcb: Longint): Longint; stdcall;
var
theStream: TMemoryStream;
begin
// dwCookie is Application-defined,
// so we're passing the stream containing
// the formatted text to be added.
//
theStream := TMemoryStream(dwCookie);
Result := 0;

with theStream do begin
if (Size = position) then begin
pcb := 0;
Exit;
end
else if (Size - Position) <= cb then begin
pcb := Size;
Read(pbBuff^, Size);
end
else begin
pcb := cb;
Read(pbBuff^, cb);
end;
end;
end;

function TGSRichEdit.FetchText(AFilename: string): integer;
var
editStream: TEditStream;
theStream: TMemoryStream;
begin
// Bring the text to be appended or inserted into a TMemoryStream;
//
theStream := TMemoryStream.Create;
try
theStream.LoadFromFile(AFilename);
theStream.Seek(0, soFromBeginning);

// Set up the edit stream.
//
editStream.dwCookie := longint(theStream);
editStream.dwError := 0;
editStream.pfnCallback := @EditStreamCallback;

// Send the EM_STREAMIN message.
//
Result := SendMessage(Handle, EM_STREAMIN, SF_RTF or SFF_SELECTION,
longint(@editStream));
finally
theStream.Free;
end;
end;

function TGSRichEdit.Append(AFilename: string): integer;
begin
// Append a lines containing a single space to the end;
Lines.Append(' ');

// Position to end of text.
//
SelStart := SendMessage(Handle, EM_LINEINDEX, Lines.Count - 1, 0);
SelLength := 1; // Select the space that we just added.

Result := FetchText(AFilename);
end;

function TGSRichEdit.Insert(AFilename: string): integer;
begin
Result := FetchText(AFilename);
end;

procedure Register;
begin
RegisterComponents('Garlin', [TGSRichEdit]);
end;

end.

bob mackey

unread,
Dec 9, 2001, 11:18:18 AM12/9/01
to

You say 'merge', but do you mean 'append'?

Have you tried:

in RichEdit1, selectAll, then copy to clipboard.
then
in RichEdit2, position the cursor, and paste from clipboard

--
bob
myName = 'bobmackey';
myISP = 'annapolis.net';
myaddress := myName + '@' + myISP;

0 new messages