Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 05-09-2008
rauros rauros is offline
Miembro
 
Registrado: feb 2008
Ubicación: Alicante - Sax / Sax - Alicante
Posts: 235
Poder: 17
rauros Va por buen camino
Bua, me he tirado toda la tarde pero mirad lo que he conseguido:

Conjunto de edits especiales para escribir ips:

Código Delphi [-]
unit EditSoloIp;

interface

Uses StdCtrls, Controls, SysUtils, Windows;

Type
  TEditByte=Class(TEdit)
  Public
  SiguienteEdit: HWnd;
  protected
  procedure KeyPress(var Key: Char); override;
End;

Type
  TEditIp=Object
  Edits: Array [1..4] of TEditByte;
  Separadores: Array [1..3] of TLabel;
  Public
  Function GetIp: String;
  Procedure SetIp(Ip: String);
  Procedure Crear(Padre: TWinControl; X: Integer; Y: Integer; Separador: Char);
End;

implementation

Function TEditIp.GetIp: String;
Begin
Result:=Edits[1].Text + '.' + Edits[2].Text + '.' + Edits[3].Text + '.' + Edits[4].Text
End;

Procedure TEditIp.SetIp(Ip: String);
Var
I,b: Integer;
Bytes: Array [1..4] of string;
Begin
IP:=Trim(ip);
I:=0;
If not (Ip[1] in ['0'..'9']) then
Begin
MessageBox(0,'Error, esa ip es incorrecta','Error IpToStr',16);
Exit;
End;
b:=1;
Repeat Inc(I);
If Ip[i] = '.' then
Inc(b)
Else If B > 4 Then Begin
MessageBox(0,'Error, esa ip es incorrecta','Error IpToStr',16);
Exit;
End Else If not (Ip[i] in ['0'..'9']) then
Begin
MessageBox(0,'Error, esa ip es incorrecta','Error IpToStr',16);
Exit;
End
Else
Bytes[b]:=Bytes[b] + Ip[i];
Until I = Length(ip);
For I := 1 to 4 do
If StrToInt(Bytes[i]) > 255 then Bytes[i]:='255';
Edits[1].Text:=bytes[1];
Edits[2].Text:=bytes[2];
Edits[3].Text:=bytes[3];
Edits[4].Text:=bytes[4];
End;

Procedure TEditByte.KeyPress(var key: Char);
Begin
If Key = ' ' then Begin
Windows.SetFocus(SiguienteEdit);
Key:=#0;
End;
If not (key in ['0'..'9',' ',Char(8),Char(46)]) then Key:=#0;
Inherited;
If Text = '' then exit;
If StrToInt(Text) > 255 Then Begin Text:='255';
Key:=#0;
End;
End;

Procedure TEditIP.Crear(Padre: TWinControl;
X: Integer; Y: Integer; Separador: Char);
Var
I: Byte;
Begin
  For I:=1 to 4 Do
  Begin
    Edits[i]:=TEditByte.Create(Padre);
    Edits[i].Parent:=Padre;
    Edits[i].Text:='255';
    Edits[i].Top:=x;
    Edits[i].Left:=y;
    Edits[i].Height:=17;
    Edits[i].Width:=25;
    Edits[i].Visible:=True;
    Y:=Y + 32;
  End;
  Y:=y - 126 + 24;
    For I:=1 to 3 Do
  Begin
    Separadores[i]:=TLabel.Create(Padre);
    Separadores[i].Parent:=Padre;
    Separadores[i].Caption:=Separador;
    Separadores[i].Top:=x;
    Separadores[i].Left:=y;
    Separadores[i].Height:=20;
    Separadores[i].Width:=4;
    Separadores[i].Font.Size:=12;
    Separadores[i].Visible:=True;
    Y:=Y + 32;
  End;
Edits[1].SiguienteEdit:=Edits[2].Handle;
Edits[2].SiguienteEdit:=Edits[3].Handle;
Edits[3].SiguienteEdit:=Edits[4].Handle;
Edits[4].SiguienteEdit:=Edits[1].Handle;
End;

End.

Un ejemplo para crearlo:

var
EditIp: TEditIp;

procedure TForm1.FormCreate(Sender: TObject);
begin
EditIp.Crear(Form1,96,296,'.');
end;
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Heredar un frame. adebonis OOP 4 21-05-2008 20:10:57
Heredar Objetos ADO mcarazas Varios 3 19-10-2006 10:07:20
Problema al heredar frames choty Varios 5 21-06-2006 17:03:47
Heredar objeto carlomagno OOP 5 19-06-2006 01:00:05
Heredar del DBNavigator Carlosj OOP 0 11-01-2005 09:29:43


La franja horaria es GMT +2. Ahora son las 06:41:33.


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