このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


RTF- Rich Text 判型 とじ込み/提出するs and Lazarus- colors HOME - - - - - Lazarus Tutorials TOC - - - - - - Other 構成要素 for programmers

Working with Rich Text 判型 とじ込み/提出するs ("RTF")

Changing the color, style, etc, of selected bits of text
(And a "特別手当" 代案/選択肢 discussion of "filestreams"!)

filename: LT4Nh-rtf.htm

This page is "browser friendly". Make your browser window as wide as you want it. The text will flow nicely for you. It is easier to read in a 狭くする window. With most browsers, 圧力(をかける)ing 加える, minus or 無 while the 支配(する)/統制する 重要な (ctrl) is held 負かす/撃墜する will change the texts size. (大きくする, 減ずる, 回復する to default, それぞれ.) (This is more fully explained, and there's another tip, at my 力/強力にする Browsing page.)

Written a bit あわてて... but Good Stuff here, I think.

As this stands, you may wonder "What is the point?"

As it stands... you're 権利! There's not a lot of point to the 使用/適用 現在のd here! As anything you'd use for its own 長所s.

So why did I 令状 it?

I was starting to build an 使用/適用 for a やめる 明確な/細部 want. It will ざっと目を通す two 類似の text とじ込み/提出するs, and 許す the 使用者 to choose which 見解/翻訳/版, where differences 存在する, to put into a final 合併するd 見解/翻訳/版 which will have elements of both of the "input" とじ込み/提出するs.

As I dreamed of what would be, I "saw" in my mind's 注目する,もくろむ, a form with two 覚え書きs on it. One for each of the input とじ込み/提出するs.

There would be just one scroll 妨げる/法廷,弁護士業... it would scroll the text in BOTH of the windows.

Where the text is 同一の, the text will be 黒人/ボイコット. Where a とじ込み/提出する has something the other とじ込み/提出する doesn't have, that text will be in green. Where there's a 封鎖する of text that appears, sort of, to be 現在の... but in different forms... in both とじ込み/提出するs, it will be in red, in both 覚え書きs.

Now.. with an ordinary TMemo 覚え書き, you can't have different bits in different colors. Nor can you have bold, italic, etc text.

Enter TRichText

Happily, however, there is a 解放する/自由な "公式の/役人" 追加する-on 一括 which gives you something やめる like a TMemo 覚え書き... the TRichMemo 覚え書き.

This essay takes you 徹底的な 追加するing the 一括, and making some use of it.

The 魔法 the colors, etc, comes to you 経由で the wonders of the .rtf とじ込み/提出する 判型. It has been around for a long time. Many 使用/適用s can open とじ込み/提出するs of this 判型 and LibreOffice Writer の中で them. A simple text editor can also open one... though you'll see "gibberish". (That "gibberish" 作品 the way the code behind a page of .html 作品. It is a markup language. 開始 either an .html 文書 or a .rtf 文書 lets you see "what's happening".

簡潔に 支援する to my goal...

((q-alt text for image))

As I said, this tutorial was born out of 研究 I was doing along the road to 令状ing an 使用/適用 that I want for my own 目的s.

That 使用/適用 will ask the 使用者 to 明示する two とじ込み/提出するs. They will 含む/封じ込める almost the same 構成要素.

The 使用/適用 will then 陳列する,発揮する them in a manner something like...





Getting started with RichMemo

Start at...

https://wiki.lazarus.freepascal.org/RichMemo

I'm assuming you already have a Lazarus IDE 任命する/導入するd on your computer.

Ever notice how the devil lurks in the 詳細(に述べる)s? I did the に引き続いて 28 Nov 20 (staying at home to help 敗北・負かす Covid) using 勝利,勝つ 10, Lazarus 2.0.0 r60307, and though it will mean nothing to you, it may help me if I 追加する "on pcVa2". (That tells me which of my computers I did this on.)

That page says...

"The easiest way to 任命する/導入する the stable 見解/翻訳/版 of the 構成要素 is 経由で the Online-一括-経営者/支配人 含むd in 現在の Lazarus 見解/翻訳/版s."

... and it says a bunch of other stuff about how you might 任命する/導入する the 一括. I didn't need to read any その上の. (The "easiest way" worked for me". I just.....)

I 開始する,打ち上げるd my Lazarus.

Did a "とじ込み/提出する/ の近くに All" so that nothing remained open in the IDE.

Invoked "一括/ Online 一括 経営者/支配人".

That brought up...

((q-alt text for image))

I typed "Rich" into the edit box to the 権利 of "Filer by", so the 経営者/支配人 would look for 一括s with 指名するs 含む/封じ込めるing "Rich". (I left the type of 一括 始める,決める for "一括s".)

That brought up a choice of "LazRichView" and "RichMemo". I went for "RichMemo": Ticked the box, invoked "任命する/導入する"... "From Repository".

That 開始する,打ち上げるd a scary (to me!) 速く passing sequence of "開始 一括"/"収集するing 一括" messages, with "Success" appearing 公正に/かなり quickly after the 開始/収集するing.


It was All Over in under a minute.

Then I was asked...

((q-alt text for image))

I gulped and said "Yes".

"Stuff" started happening. It looked a bit like when you 開始する,打ち上げる a 収集する/run 操作/手術 when using the IDE. LOTS of 警告s in the "Messages" dialog, but 結局 It All Went Away, and Lazarus 再開するd. (I was typing this at the time. 焦点(を合わせる) may have switched to Lazarus without me noticing. I may have unwittingly said "Proceed", and thus lost the chance to 診察する the messages when the "再構築する... Normal" had finished.)

I was left looking at what seemed to be my usual Lazarus IDE. Ran an old 事業/計画(する). All seemed to be 井戸/弁護士席. (Then, and subsequently. Don't worry about the "seemed"!)

RTF

Time to talk about "RTF".

As I started to say earlier, "RTF" is an old とじ込み/提出する 判型. The letters stand for Rich Text 判型.

It 作品 a bit like HTML. There is plain text "behind" what you see on the 審査する if you 負担 a とじ込み/提出する of RTF 構成要素 into an editor that knows how RTF should be 陳列する,発揮するd.

Hello RTF World

Use an ordinary simple text editor... Notepad if you must, Textpad if you'll take my advice... to create a little とじ込み/提出する called "TestData.txt". Yes... just a simple .txt とじ込み/提出する... for now! Save it in the directory you are using for your Lazarus program.

Put 正確に/まさに the に引き続いて in it...


Hello RTF world.

実験(する) とじ込み/提出する for the TRichMenu 構成要素.

(I said "正確に/まさに".. But as long as "RTF" appears somewhere, and the とじ込み/提出する is at least 32 characters long, it will "work"... but the button to change the words "とじ込み/提出する for" so they are red on the 審査する might make different characters red.)

Start a new 使用/適用 in your recently 延長するd Lazarus. I called 地雷 "LTN163-rtf".

Put a button on it. Call it buLoadTxtFile.

The 構成要素 palette's "ありふれた 支配(する)/統制するs" should be 申し込む/申し出ing a new 構成要素 now...

((q-alt text for image))

The tooltip should say "TRichMemo".

Make the button of your little Lazarus 実験(する) 使用/適用 do...


手続き TLTN163-rtfF1.buLoadTxtFileClick(Sender: TObject);

begin

  RichMemo1.Lines.LoadFromFile('TestData.txt');

end;

Run that, click the button. The text should 負担 into the RichMemo, and be 明白な to the 使用者... but everything will be 黒人/ボイコット for the time 存在.

追加する another button. Call it buFindForThe.

[=== Digression begins: 権利! Up to there, things raced along almost as 急速な/放蕩な as you've just read them. The next bit was "supposed" to be simple. Ha! I'd already "研究d" the 問題/発行するs, and it was "平易な". Three hours later I has something working. Aren't computers "fun".
--- Digression Ends===]

"All" I 手配中の,お尋ね者 was to turn some of the text a different color. 恐らく, to turn 5 characters, from the 3rd character in the 覚え書き, blue, all I needed was...

手続き TLDN163rtfF1.DoesNotWorkClick(Sender: TObject);

var fontTmp:TFont;

begin

  fontTmp:=RichMemo1.font;//To fill all of the 所有物/資産/財産s with "starting values".

  fontTmp.Color:=clBlue;//Change the font color

  RichMemo1.SetTextAttributes(3,5,fontTmp);

end; 

It "作品"... to change ALL of the text red! によれば the web, the 3,5 should have made it happen to just a 範囲 of characters. Sigh. (See https://wiki.freepascal.org/RichMemo#SetTextAttributes

A little "gotcha"... there may 井戸/弁護士席 be subtle differences between how the 使用/適用 作品 on machines with different operating systems. Sigh. That it even tries to be multi-壇・綱領・公約 is, to me, very impressive. I'll happily settle for a わずかに imperfect success... so far!... for the chance that I can move to Linux from wretched Windows someday, and carry on programming in Lazarus without major re-leaning.

This 作品...

結局 I gave up trying to 人物/姿/数字 out why the 3 and the 5 were 存在 ignored.

The に引き続いて 作品. In it, I've made one bit of the text red, another green. I used a simple method and a fancy method to 決定する what part of the text will change color.

The same basic word... SetRangeColor... was used for both. Then only difference is in the setting of the two numbers which, between them, 決定する what part of the text will be colored.

In the simple method it is just that 8 characters from the 22nd in the text will be made red.

In the second, if "RTF" appears in the text, the first instance of those letters will be made green.

You can, by the way, use 類似の techniques to make bits of text "bold", "を強調するd", etc... or not. Or so I am told. Ha!

The に引き続いて DOES WORK! At least today, under Win10.

手続き TLDN163rtfF1.buChangeColorsClick(Sender: TObject);

var boTmp:boolean;//Not 厳密に necessary... used to make code more readable

   iTextStart,iTextLength:integer;

   soSearchOptions:TSearchOptions;

begin

(*SPENT AGES TRYING TO GET "RichMemo1.SetTextAttributes" to work. No joy.

  See 積みすぎる "SetTextAttributes" other form for more Good Stuff

  https://wiki.freepascal.org/RichMemo#SetRangeColor  *)



//に引き続いて starts with the 22nd character in the Rich(実験(する))覚え書き,

    //   and colors 8 characters blue.

  RichMemo1.SetRangeColor(22,8,clRed);



//Fancier... but only in how "start", "length" 決定するd.

  //See https://wiki.freepascal.org/RichMemo#Search

  //SearchOptions:

  //https://sourceforge.逮捕する/p/lazarus-ccr/svn/3771/tree//構成要素s/richmemo/richmemo.pas

  //   TSearchOption = (soMatchCase, soWholeWord, soBackward);

  //   TSearchOptions = 始める,決める of TSearchOption;



soSearchOptions:=[];//準備する a value to pass in the 4th parameter.

boTmp:=RichMemo1.Search('RTF',0,999,soSearchOptions,iTextStart,iTextLength);

if boTmp then begin

   RichMemo1.SetRangeColor(iTextStart,iTextLength,clGreen);

   laMsg.caption:='';//laMsg not 批判的な to changing the color.

      //See what "else" 条項 to learn what laMsg is for.

   end//no ; here

 else begin

   laMsg.caption:='String "RTF" not 設立する';

   end;//else



end;//proc buChangeColorsClick

So! That's how to color bits of the text in a TRichMemo 構成要素.

Running into the surf

Ever feel like you are running into the surf? Something starts やめる 井戸/弁護士席, but just gets harder and harder, leaving you closer and closer to Just Giving Up.

So it was with this 事業/計画(する). Started remarkably 滑らかに. (I can't remember the last time (before 11/10) that I 追加するd an extra library to my IDE. (I shy away from doing it, for 推論する/理由s that seem good to me.) And that went swimmingly.

The "simple" 事柄 of coloring text was a bit recalcitrant.

And then I reached the final challenge needed to (手先の)技術 a 完全にする result: A way to save the tweaked text from the TRichEdit 覚え書き 支援する to a disk とじ込み/提出する.

I'd failed to 計画(する), in 詳細(に述べる), where I was going.

Did I want to save the text as plain text, thus losing the colors, the italics, etc, I'd 適用するd to help me work on the text? Or did I want to save it in the RTF 判型 which I'd been using while the text was on the 審査する for editing.

I hadn't really thought about that.

When I started thinking about it, I realized that いつかs I'd want the one, other times, the other. (存在 human, I 手配中の,お尋ね者, as usual, to have it both ways!)

As it turns out, both are reasonably 平易な to do.

You have to understand working with filestreams... not a forte of 地雷, にもかかわらず my earlier tutorial about filestreams. (Which is, at 11/20, nothing more than a working デモ 使用/適用, with sourcecode and some inline documentation.)

The idea of "filestreams", as I understand it, is that they are "abstracted" とじ込み/提出するs. When you speak of a とじ込み/提出する on your hard 運動, or a とじ込み/提出する 負担d into a 覚え書き, or in the computers RAM, there are differences. If you take a step 支援する, and take about what's in one of those とじ込み/提出するs as a filestream, there are almost no differences arising from where the とじ込み/提出する is.

This is GOOD! Now, everything you learn about a filesteam will be useful to you when thinking about "とじ込み/提出するs" in or on (at least) three places/ surfaces.

And the language has ways to take a とじ込み/提出する on a disk, make it a filestream, move it to, say, a 覚え書き.

Save as RTF

The に引き続いて moves the text in our TRichMemo, 蓄える/店 in on the hard 運動, in the RTF 判型....

手続き TLDN163rtfF1.buSaveToFile_WITH_RTFClick(Sender: TObject);

//From http://lazplanet.blogspot.com/2013/12/create-rich-text-editor-for-yourself.html

//HA! WORKS!

//AND MUCH BETTER THAN MINE, anyway, even apart from fact 地雷 didn't save the RTF info.



var

  fs : TFileStream;

begin

  //if SaveDialog1.遂行する/発効させる then begin

    fs := nil;

    try

//      fs := TFileStream.Create( Utf8ToAnsi(SaveDialog1.FileName), fmCreate);

    fs := TFileStream.Create( Utf8ToAnsi('TmpDemo.rtf'), fmCreate);



    RichMemo1.SaveRichText(fs);

      //Saved:=True;

      //Filename:=ExtractFileName(SaveDialog1.FileName);

      //Filepath:=ExtractFilePath(SaveDialog1.FileName);

      //Caption:=Filename;

    except

    end;

    fs.解放する/自由な;

 // end;   //if SaveDialog1.遂行する/発効させる

end;

Save as simple text

The に引き続いて moves the text in our TRichMemo, 蓄える/店 in on the hard 運動, in the RTF 判型. As 現在のd, it always saves the text to "TmpDemo.rtf", in the same directory as the .exe is in. (And it will... without asking or 警告... over-令状 any とじ込み/提出する of that 指名する already in the folder.) If you put the 権利 選択 of remmed out lines 支援する and rem out at least one of the 現在の lines, you will have a more 一般に useful 手続き. I adapted it as I have to "(土地などの)細長い一片 it 負かす/撃墜する" to basics.

手続き TLDN163rtfF1.buSaveToFile_NO_RTFClick(Sender: TObject);

//I'd hoped I could just do...

//    RichMemo1.SaveRichText('TmpDemo.rtf');

//... but of course that would be too 平易な.



//See also:https://sheepdogguides.com/lut/lt2Ne-filestreams.htm



//Adapted from example at http://wiki.freepascal.org/TFileStream

//N.B.... This will not work without some 改良 if another

//  使用/適用 has the 生産(高) とじ込み/提出する open/ locked when this 使用/適用

//  tries to 令状 to it.



(*THE FOLLOWING DOES ** NOT ** SAVE the "rtf markup". It only

saves the text. 非,不,無 of the colors you 追加するd to it while it was

in the TRichMemo 覚え書き will still be there!



As it happens... that's all I needed!!



I 嫌疑者,容疑者/疑う others will want the "hidden stuff" that would 原因(となる) the

とじ込み/提出する, on 存在 reloaded (into an RTF-有能な editor, like Libre Office),

to still have the colorings 始める,決める 以前.



This isn't "clever": It always saves the text to "TmpDemp.txt". "直す/買収する,八百長をするing"

that is a separate 問題/発行する, left out of this so that you can see

the heart of what is going on.

*)



var strm: TFileStream;

    bTmpL:byte;

    liLineInMemo,liPosnInLine:longint;

    sTmpL:string;

begin //buSaveToRTFfileClick

try //1

      strm := TFileStream.Create(Utf8ToAnsi('TmpDemo.txt'), fmCreate );//N.B.This will overwrite any 存在するing とじ込み/提出する

      strm.position:=0;

      liLineInMemo:=0;//Line "0" is first line in MEMO. (公式文書,認める 索引ing

      //difference between lines in 覚え書きs and characters in string)

        try //2

        repeat

          sTmpL:=RichMemo1.lines[liLineInMemo];

          for liPosnInLine:=1 to length(sTmpL) do begin //For...

              bTmpL:=ord(sTmpL[liPosnInLine]);//sTmpL[1] is 1st char in string.

              strm.WriteByte(bTmpL);

              end;//For...

          inc(liLineInMemo);

          strm.WriteByte(13);//挿入する CR in 生産(高)

          strm.WriteByte(10);//挿入する LF in 生産(高)

        until liLineInMemo=RichMemo1.Lines.count;

      except//2

        on e:Exception do showmessage('problem... 17a21a');

      end;//e

    except //1

      on e:Exception do showmessage('problem... 17a21b');

    end;//try "1"

      FreeAndNil(strm);

end;//buSaveToFile_NO_RTFClick

How are "RTF" and "plain text" different?

If you put 負担 copies of a simple text which has been saved from the 使用/適用 we have been discussing into Libre Office Writer, they look pretty 類似の, except that the some of the text in the .rtf is in color. (Fancier use of the RTF would also 許す fonts, different letter sizes, etc.)

If you look at them with a simple text editor, you get the に引き続いて from the .txt とじ込み/提出する...

To show how RTF and simple text look "under

the 肌.

And this from the .rtf とじ込み/提出する. (I have changed where new lines start, and 追加するd some indents.)

{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang2057

    {\fonttbl{\f0\fnil\fcharset0 Segoe UI;}{\f1\fnil Segoe UI;

    }

}

{\colortbl ;\red0\green128\blue0;\red255\green0\blue0;}

{\*\発生させる人(物) Riched20 10.0.19041}\viewkind4\uc1 \pard\f0\fs18

To show how

    \cf1 RTF\cf0  and si\cf2 mple tex\cf0 t

    look "under the 肌.\f1\par\par

}

Each has its uses.



Sourcecode 供給するd

You can download a .zip とじ込み/提出する (LDN163rtf.zip) with the example of using RTF (and filestreams!). It has all the sourcecode, and a copy of the 収集するd .exe, 同様に, so you can have a play with that even before you bother to 解雇する/砲火/射撃 up your Lazarus.





Search across all my 場所/位置s with the Google search...

Custom Search


To search THIS 場所/位置.... (Go to my other 場所/位置s, below, and use their search buttons if you want to search them.)

索引 sitemap 前進するd
search engine by freefind

場所/位置 地図/計画する    What's New    Search

The search engine 単に looks for the words you type, so....
*    (一定の)期間 them 適切に.
*    Don't bother with "How do I get rich?" That will 単に return pages with "how", "do", "I"....

Please also 公式文書,認める that I have two other 場所/位置s, and that this search will not 含む them. They have their own search buttons.

My SheepdogSoftware.co.uk 場所/位置.

My 場所/位置 at Arunet.


広告 from page's editor: Yes.. I do enjoy 収集するing these things for you. I hope they are helpful. However... this doesn't 支払う/賃金 my 法案s!!! Sheepdog ソフトウェア is supposed to help do that, so if you 設立する this stuff useful, (and you run a Windows or MS-DOS PC) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!
Click here to visit editor's freeware, shareware page.

Link to Lazarus Tutorials main page

To email this page's editor, Tom Boyd.... Editor's email 演説(する)/住所. Suggestions welcomed! Please 特記する/引用する "LT4Nh-rtf.htm".




Valid HTML 4.01 Transitional Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.

AND passes... Valid CSS!

If this page 原因(となる)s a script to run, why? Because of things like Google パネル盤s, and the code for the search button. Why do I について言及する scripts? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....