Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   TMaskEdit y mascara para IP (https://www.clubdelphi.com/foros/showthread.php?t=83703)

mjjj 17-07-2013 17:45:03

TMaskEdit y mascara para IP
 
Estimados, quiero utilizar un maskedit para ingresar una dirección IP.
La mascara que utilicé es 999.999.999.999;1:_

Pero tiene un problema, por ejemplo cuando ingreso 192.23.2.123, y asignar el texto del componente me arroja 192. 23. 2.123

Que mascara utilizarían ustedes?

ecfisa 17-07-2013 18:32:15

Hola mjjj.

Revisa si te sirve el ejemplo de este enlace de Embarcadero : MaskEdit.

Otra opción es usar el IP address control de windows, aca tenes un ejemplo: ...use the IP Address Control in a Form?.

Saludos :)

ecfisa 17-07-2013 19:18:24

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. :)


La franja horaria es GMT +2. Ahora son las 21:53:16.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi