Skip to main content
adicionou 7 caracteres ao conteúdo
Fonte Link
Tmc
  • 2,5mil
  • 3
  • 25
  • 46
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, PColunaWSCount, 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;
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, PColuna: 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;
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;
removeu 94 caracteres do conteúdo
Fonte Link
Tmc
  • 2,5mil
  • 3
  • 25
  • 46
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 MemoAdjustment(var AMemo: TMemo);
    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.MemoAdjustmentMemo1KeyPress(Sender: TObject; var AMemoKey: TMemoChar);
var i, WSCountILine, WSAddPColuna: Integer;
begin
  WSCount := GetMaxCharacterCleanWhiteSpace(Memo1); 

  forif iKey := 0 to AMemo.Lines.Count -#13 1then do
    beginBegin
      WSAddILine := WSCount - LengthGetCurrentLine(AMemo.Lines[i]Memo1); - 1;

      AMemo.Lines[i]WSCount := AMemo.Lines[i] + WhiteSpaceCountGetMaxCharacter(WSAddMemo1); 
    end;
end;

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var ILine,WSAdd PColuna:= Integer;
begin
WSCount - CleanWhiteSpaceLength(Memo1.Lines[ILine]); 

  if Key   Memo1.Lines[ILine] := #13Memo1.Lines[ILine] then+ MemoAdjustmentWhiteSpaceCount(Memo1WSAdd);
    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

Correção da tecla enter, antes saltava linhas ou não avançava.

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 MemoAdjustment(var AMemo: TMemo);
    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.MemoAdjustment(var AMemo: TMemo);
var i, WSCount, WSAdd: Integer;
begin
  WSCount := GetMaxCharacter(Memo1);

  for i := 0 to AMemo.Lines.Count - 1 do
    begin
      WSAdd := WSCount - Length(AMemo.Lines[i]); 
      AMemo.Lines[i] := AMemo.Lines[i] + WhiteSpaceCount(WSAdd); 
    end;
end;

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var ILine, PColuna: Integer;
begin
  CleanWhiteSpace(Memo1); 

  if Key = #13 then MemoAdjustment(Memo1);   
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;
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, PColuna: 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

Correção da tecla enter, antes saltava linhas ou não avançava.

Fonte Link
Tmc
  • 2,5mil
  • 3
  • 25
  • 46

Com a ajuda do @VictorZanella e da sua resposta desenvolvi o Projecto ainda não esta a 100%, mas já faz o que desejava, quando terminar eu actualizo:

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 MemoAdjustment(var AMemo: TMemo);
    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.MemoAdjustment(var AMemo: TMemo);
var i, WSCount, WSAdd: Integer;
begin
  WSCount := GetMaxCharacter(Memo1);

  for i := 0 to AMemo.Lines.Count - 1 do
    begin
      WSAdd := WSCount - Length(AMemo.Lines[i]); 
      AMemo.Lines[i] := AMemo.Lines[i] + WhiteSpaceCount(WSAdd); 
    end;
end;

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var ILine, PColuna: Integer;
begin
  CleanWhiteSpace(Memo1); 

  if Key = #13 then MemoAdjustment(Memo1);   
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;