
This component has the standard properties of a Windows rich text edit box. Its standard file format is rich text (RTF).
This property controls the way a RichEdit box occupies the space of a form. The possible settings are:
This controls the alignment of text in a RichEdit control: left, centred or right aligned (justified). Individual lines of text respond to separate alignment commands e.g. Ctrl-E (centre), Ctrl-R (right) and Ctrl-L (left).
There are just two styles, Single and None. Single BorderStyle can be affected by the Bevel setting.
This allows the cursor shape to be changed when it is over the RichEdit control. For text editing the I-beam cursor might be a good choice.
This allows the contents of a RichEdit control to be set up at design time. Lines is a TStrings object so TStrings properties and methods can be used to manipulate lines in a RichEdit control. These properties include Count, Add, Append and Delete (see online Help for a full list).
These properties allow selected text to be manipulated. The SelStart property supplies the start position of selected text within a block of text. The SelLength property supplies the length of the selected text in bytes. The SelText property contains the text that has been selected.
This property decides whether the user can enter Returns by pressing the Return key (True).
This property determines whether the text will wrap from line to line (True).
Clears a RichEdit control of all text.
Searches a range of text for a given section of text.
Prints the contents of a RichEdit control.
Here is some code that reads data from a file into a rich edit control (it could equally be a memo). It sets up an array of records and writes them to a file. It reads the data backf rom the file and then prints the contents of the memo.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, printers;
type
myrecord=record
name:string[20];
score:string[4];
howout:string[10];
end;
Tmyfile=file of myrecord;
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
PrintDialog1: TPrintDialog;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
myarray:array[1..5] of myrecord;
myfile:Tmyfile;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
line:string;
begin
richedit1.Visible:=true; //show the richedit
assignfile(myfile,'myfile.txt');
reset(myfile);
for i:= 1 to 5 do
begin
read(myfile,myarray[i]); //read from file into array
//make a string for a line in the richedit box
line:=myarray[i].name+' '+ myarray[i].score + ' '+ myarray[i].howout;
richedit1.lines.Add(line) //add string to list box
end;
if PrintDialog1.Execute then //start print routine
with Printer do
begin
BeginDoc;
for i:=0 to richedit1.Lines.Count do
Canvas.TextOut(200,200 + //standard code to print contents of a control
(i * Canvas.TextHeight(richedit1.Lines.Strings[i])),richedit1.Lines.Strings[i]);
Refresh;
EndDoc;
end;
richedit1.Visible:=false; //hide the richedit
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
myarray[1].name:='fred';
myarray[1].score:='5';
myarray[1].howout:='bowled';
myarray[2].name:='tom';
myarray[2].score:='6';
myarray[2].howout:='LBW';
myarray[3].name:='dan';
myarray[3].score:='7';
myarray[3].howout:='caught';
myarray[4].name:='bart';
myarray[4].score:='8';
myarray[4].howout:='run out';
myarray[5].name:='george';
myarray[5].score:='9';
myarray[5].howout:='stumped';
assignfile(myfile,'myfile.txt');
rewrite(myfile);
for i:= 1 to 5 do
write(myfile,myarray[i]);
end;
end.