Ver Mensaje Individual
  #8  
Antiguo 22-11-2008
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Reputación: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
Lo de impedir el cambio de línea sólo si se completaban los tres caracteres lo había puesto justamente por no saber con exactitud cuáles eran las necesidades, pero puedes modificarlo fácilmente:

Código Delphi [-]
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var
  C, I: Integer;

begin
  I := Memo1.Perform(EM_LINEFROMCHAR, Memo1.SelStart, 0);
  C := Length(Memo1.Lines[i]);

  if (Key = #13) and (C >= 3) then
    Key := #0;

  if (C >= 3) and (Key <> #8) then
    Memo1.Lines.Insert(I + 1, '');
end;

Pero, por lo que comentas, te reitero que no creo que el Memo sea el componente adecuado. Podrías, por ejemplo, usar un StringGrid con una sola columna editable y una sóla fila editable:

ColCount = 2
RowCount = 2
FixedCols = 1
FixedRows = 1

y el siguiente código en su evento KeyPress:

Código Delphi [-]
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
var
  C: Integer;

begin
  C := Length(StringGrid1.Cells[StringGrid1.Col, StringGrid1.Row]);

  if (Key = #13) then
  begin
    if StringGrid1.Row = StringGrid1.RowCount - 1 then
      StringGrid1.RowCount := StringGrid1.RowCount + 1;

    StringGrid1.Row := StringGrid1.Row + 1;
  end
  else if (C >= 3) and (Key <> #8) then
    Key := #0;
end;

Con esto, partes de una sóla celda y conforme el usuario oprime ENTER -sin importar si hay uno, dos o tres caracteres- se pasa a la fila siguiente (si era la última fila, se crea una nueva). Tienes mucha más libertad para moverte por entre las celdas si hay que editar algo, sin el riesgo de descuadrar cosas.

La fila y columna fija puedes usarla para poner rótulos, o bien te olvidas de ellas poniendo:

ColCount = 1
RowCount = 1
FixedCols = 0
FixedRows = 0

// Saludos
Responder Con Cita