With the help of @VictorZanella and your answer I developed the Project is not yet 100%, but already does what I wanted, when I finish I update:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure Memo1KeyPress(Sender: TObject; var Key: Char);
procedure Memo1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
private
function GetCurrentLine(AMemo: TMemo): Integer;
function whiteSpaceCount(ASpaces: Integer): String;
function GetMaxCharacter(AMemo: TMemo): Integer;
procedure CleanWhiteSpace(var AMemo: TMemo);
procedure CreateWhiteSpace(var AMemo: TMemo);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GetCurrentLine(AMemo: TMemo): Integer;
Var Coordinate: TPoint;
Begin
Coordinate := AMemo.CaretPos;
Result := Coordinate.Y + 1;
End;
function TForm1.GetMaxCharacter(AMemo: TMemo): Integer;
Var MaxChar: Integer;
Begin
MaxChar := (AMemo.Width div 7) - 1; //feito para font_name := "courier new"; size := "8"
Result := MaxChar;
End;
function TForm1.WhiteSpaceCount(ASpaces: Integer): String;
var i: Integer;
begin
Result := '';
for i := 1 to ASpaces do Result := Result + ' ';
end;
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var ILine, WSCount, WSAdd: Integer;
begin
CleanWhiteSpace(Memo1);
if Key = #13 then
Begin
ILine := GetCurrentLine(Memo1) - 1;
WSCount := GetMaxCharacter(Memo1);
WSAdd := WSCount - Length(Memo1.Lines[ILine]);
Memo1.Lines[ILine] := Memo1.Lines[ILine] + WhiteSpaceCount(WSAdd);
End;
end;
procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
CreateWhiteSpace(Memo1);
end;
procedure TForm1.CreateWhiteSpace(AMemo: TMemo);
var ILine, ILine2, PColuna, WSAdd, WSCount: Integer;
Begin
ILine2 := GetCurrentLine(AMemo);
PColuna := Amemo.SelStart - Perform(EM_LINEINDEX, ILine2, 0);
ILine := GetCurrentLine(AMemo) - 1;
WSCount := GetMaxCharacter(AMemo);
WSAdd := WSCount - Length(AMemo.Lines[ILine]);
AMemo.Lines[ILine] := AMemo.Lines[ILine] + WhiteSpaceCount(WSAdd);
Amemo.SelStart := Perform(EM_LINEINDEX, ILine2, 0) + PColuna;
End;
procedure TForm1.CleanWhiteSpace(var AMemo: TMemo);
var ILine, PColuna: Integer;
SLine, CLine: String;
begin
ILine := GetCurrentLine(AMemo);
SLine := AMemo.Lines.Strings[ILine - 1];
SLine := Copy(SLine, GetMaxCharacter(AMemo)-2, 2);
if SLine = ' ' then
Begin
PColuna := AMemo.SelStart - Perform(EM_LINEINDEX, ILine, 0);
CLine := AMemo.lines[ILine - 1];
CLine := copy(CLine, 1, Length(CLine) - 1);
AMemo.lines[ILine - 1] := CLine;
AMemo.SelStart := Perform(EM_LINEINDEX, ILine, 0) + PColuna;
End;
end;
UPDATE 1
Correcting the key enter
, before jumping lines or not advancing.