Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-05-2017, 01:47 PM
robert robert is offline
Senior Member
 
Join Date: Sep 2014
Posts: 366
Default First Letter Capital

How to get First letter of first word capital in each line of Memo.
Reply With Quote
  #2  
Old 01-05-2017, 09:18 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 277
Default

Loop through the lines
use Copy to get the 1st letter of each line
Check its ASCII valve and change if necessary.

Cheers Wallace
Reply With Quote
  #3  
Old 01-06-2017, 01:06 AM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 157
Default

The following capitalizes the first character you type in the memo, any character you type after the enter key or after a period/exclamation point or question mark.
Code:
type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure Memo1KeyPress(Sender: TObject; var Key: Char);
  private
    function GetCharFromString(I: Integer; const S: String): Char;
    function DoCapitalize(CurrentCaretPos: Integer; const S: String): Boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.DoCapitalize(CurrentCaretPos: Integer; const S: String): Boolean;
var
   I: Integer;
   C: Char;
 begin
   Result := False;
   if (CurrentCaretPos = 0) or (trim(S) = '') then
     Result := True
   else
   begin
     for I := CurrentCaretPos downto 1 do
     begin
       C := GetCharFromString(I, S);
       if C in [' ', #9] then
         continue
       else if C in ['.','!','?',#10,#13] then
       begin
         Result := True;
         Break;
       end
       else
         Break;
     end;
   end;
 end;

function TForm1.GetCharFromString(I: Integer; const S: String): Char;
begin
  Result := S[I];
end;

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  if DoCapitalize(Memo1.SelStart, Copy(Memo1.Text, 1, Memo1.SelStart)) then
    Key := UpCase(Key);
end;

end.

Last edited by rojam; 01-06-2017 at 03:04 AM.
Reply With Quote
  #4  
Old 01-06-2017, 04:15 AM
robert robert is offline
Senior Member
 
Join Date: Sep 2014
Posts: 366
Default

Thanks a lot but there is no Key event for Memo1. Memo1 is already filled with Text lines and when I copy Memo1 lines to Memo2 then each line word should have first letter Capital in Memo2.
Reply With Quote
  #5  
Old 01-06-2017, 12:17 PM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 157
Default

Quote:
Originally Posted by robert View Post
Thanks a lot but there is no Key event for Memo1. Memo1 is already filled with Text lines and when I copy Memo1 lines to Memo2 then each line word should have first letter Capital in Memo2.
Then try to code what @Marsheng provided. If you get stuck, then ask.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:20 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.