Delphi Topics
Some Delphi code snippets aimed primarily at the novice Delphi user
- TPageControl
- RichEdit Formatting
- Colors Standard List
- Conversions Hex to Bin
- Conversions Hex to Int
- DBLookupListBox and DBLookupComboBox
- KeyCodes
- StringLists Loading and saving
- StringLists Short Term
- StringLists Long Term
- Strings Address
- Strings Copy
- Strings In Case Select
- Strings Change File Extension
- File Operations Binary read/write
TPageControl Example
This is a simple example to demonstrate some of the formatting parameters for the TRichEdit control. Download Project
{----------------------------------------------------------------------------- Unit Name: RichUnit1 Author: Tony Domigan DOMAJ Pty. Ltd. Purpose: Demonstrate TRichEdit Formattting History: -----------------------------------------------------------------------------} unit RichUnit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, AppEvnts, StdCtrls,ExtCtrls, ComCtrls ; type TForm1 = class(TForm) Button1: TButton; ApplicationEvents1: TApplicationEvents; RichTest: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure ApplicationEvents1Exception(Sender: TObject; E: Exception); procedure FormDestroy(Sender: TObject); procedure RichTestClick(Sender: TObject); private { Private declarations } public slErrorLog: TStrings; FCre8LogFile: Boolean; FAllowResizing: Boolean; property Cre8LogFile: Boolean read FCre8LogFile write FCre8LogFile; { Public declarations } end; var Form1: TForm1; implementation uses SPConsts; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin Close; end; procedure TForm1.FormCreate(Sender: TObject); begin Cre8LogFile := True; end; procedure TForm1.ApplicationEvents1Exception(Sender: TObject; E: Exception); begin if not Cre8LogFile then Exit; with slErrorLog do begin Add(Format('%s: %s',[SDelphiErrorMessage, E.Message])); Add(Format('%s: %d %s',[SWindowsErrorCodeAndMessage, GetLastError, SysErrorMessage(GetLastError)])); Add(DateTimeToStr(Now)); Add(TimeToStr(Now)); Add(''); end; end; procedure TForm1.FormDestroy(Sender: TObject); begin if not Cre8LogFile then Exit; if Assigned(slErrorLog) then begin if slErrorLog.Count>0 then slErrorLog.SaveToFile(Format('%s.txt', [SAppErrorLog])); slErrorLog.Free; end; end; procedure TForm1.RichTestClick(Sender: TObject); const cS: String = '01234 567890 abcde fghijk lmnop qrs tuv wxyz. '; var iIterate:Integer; begin with TRichEdit.Create(Self) do begin Parent := Self; Align := alClient; Lines.Clear; Lines.Add('Use Bullet Points:'); // set numbering style Paragraph.Numbering := nsBullet; for iIterate:=0 to 4 do Lines.Add(cS); //disable bullets and set alignment centre. Paragraph.Numbering := nsNone; Paragraph.Alignment := taCenter; Lines.Add('Alignment(Centred):'); //set alignment left Paragraph.Alignment := taLeftJustify; Lines.Add('Left Aligned'); //set alignment right Paragraph.Alignment := taRightJustify; Lines.Add('Right Aligned'); //set alignment left Paragraph.Alignment := taLeftJustify; //set right and left indents to 100 Paragraph.RightIndent := 100; Paragraph.LeftIndent := 100; Lines.Add('Para Indent: '+cS+cS+cS+cS+cS); //reset left indent to 60 Paragraph.FirstIndent := 60; Lines.Add('Para Indent: '+cS+cS+cS+cS+cS); //reset left indent to 0 Paragraph.LeftIndent := 0; Lines.Add('Second Line (indented by 0 but firstIndent still active)'); //reset firstindent to 0 Paragraph.FirstIndent := 0; Lines.Add('Third Line (indented by 0 but firstIndent is 0)'); end; end; end. |
The project code resides in a button on an otherwise empty form.See below for the screen output.


