trichview.com

trichview.support




Re: RTF for numbered lists?


Return to index


Author

Message

Martin Holmes

Posted: 03/16/2004 23:25:48


Hi there,


Here's my function, which I adapted from somewhere on the Web. My guess

is that Sergei's will be superior, though:


procedure PutRTFOnClipboard(RTFTokens: string);

var

   ClipText: string;

   Data: THandle;

   DataPtr: PChar;

   CF_RTF : Word;

begin

   CF_RTF := RegisterClipboardFormat('Rich Text Format');

   ClipText := Clipboard.AsText;

   Clipboard.Open;

   try

     // Allocate appropriate memory block

     Data := GlobalAlloc(GMEM_MOVEABLE, Length(RTFTokens));

     try

       // Lock memory block

       DataPtr := GlobalLock(Data);

       try

         // Copy string to locked memory block

         Move(RTFTokens[1], DataPtr^, Length(RTFTokens));

         // Copy block into clipboard

         Clipboard.SetAsHandle(CF_RTF, Data);

         // let's be nice and restore the text

         Clipboard.AsText := ClipText;

       finally

         GlobalUnlock(Data);        // Unlock memory block

       end;

     except

         GlobalFree(Data);         // free on exception

       raise

     end;

   finally

     Clipboard.Close;              // Close clipboard

   end;

end;


Many thanks for your code!


Cheers,

Martin


Daniel Albuschat wrote:

> Martin Holmes <mholmes@uvic.ca> wrote:

>

>>Hi there,

>>

>>Does anyone know what the simplest RTF token code would be for creating

>

>

>>a numbered list? I'd like to put a sequence of questions on the

>>clipboard in RTF format, for pasting into a word-processor document, and

>

>

>>the code I see produced by Word for numbered lists is horrendously

>>complicated. I'de just like something that's autonumbering with a

>>hanging indent, or failing that, manually numbered with a hanging indent.

>

>

> I think a simple List will be like

>

> {\rtf1\ansi

>    {\listtext\plain 1.\tab}\plain foo\par

>    {\listtext\plain 2.\tab}\plain bar

> }

>

> sorry, I don't know about autonumbering.

>

> In exchange, would you show me the code you're using to

> copy the rtf to the clipboard? ;-)

> I'm doing something very similar at the moment (copying a

> url to the clipboard to insert them to a TRichViewEdit),

> but I get strange crashes when

> calling SetClipboardData... I couldn't figure out what's

> wrong.

>

> thanks,

>    Daniel





Powered by ABC Amber Outlook Express Converter