Ver Mensaje Individual
  #3  
Antiguo 17-07-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola mjjj.

Se me ocurrió otra opción usando cuatro TEdit (para el ejemplo: Edit1, Edit2, Edit3 y Edit4).

Código Delphi [-]
...
implementation

function MakeIP(Oct: array of string): string;
var
  i: Integer;
begin
  for i:= Low(Oct) to High(Oct) do
   Result := Result + Oct[i] + '.';
  SetLength(Result, Length(Result)-1);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
  Ed: TEdit;
begin
  for i:= 1 to 4 do
  begin
    Ed := TEdit(FindComponent('Edit'+IntToStr(i)));
    Ed.MaxLength := 3;
    SetWindowLong(Ed.Handle, GWL_STYLE,
      GetWindowLong(Ed.Handle, GWL_STYLE) + ES_NUMBER);
  end;
end;

// Evento asignado a los 4 edits
procedure TForm1.EditExit(Sender: TObject);
begin
  if not (StrToInt(TEdit(Sender).Text) in [0..255]) then
  begin
    TEdit(Sender).SetFocus;
    raise Exception.Create('Valor fuera de rango');
  end;
end;
...
Llamada de ejemplo:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(MakeIP([Edit1.Text, Edit2.Text, Edit3.Text, Edit4.Text]));
end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita