由于项目需要写了一个IP地址和一个MAC地址控件,欢迎大家下载,有问题请指教http://www.csdn.net/cnshare/soft/13/13985.shtm
http://wangy.vip.sina.com/mylib/yylib.rar在IP地址控件中有一个Mask属性,是我用来生成子网掩码的。
控件得到IP的每个子段的用byte表示;MAC的每个子段用string[2]表示。
没有完全返回值,若你做了修改别忘了告诉我分数太多,顺便散点
http://wangy.vip.sina.com/mylib/yylib.rar在IP地址控件中有一个Mask属性,是我用来生成子网掩码的。
控件得到IP的每个子段的用byte表示;MAC的每个子段用string[2]表示。
没有完全返回值,若你做了修改别忘了告诉我分数太多,顺便散点
解决方案 »
- 请教2表连接的sql语句
- 程序弹出异常时,如何在本程序中把这个整个屏幕抓下来。
- 打印票据,关于打印机走纸的问题
- 如何做一个软件的试用版本,功能完全开放,但有n天时间限制
- 请问怎么样取得字符串中从后面开始的五位字符函数啊??一票独得30分
- 求实现方法
- 算法讨论
- 怎样看 沙特vs德国的比赛?0:8的结果让人……
- 如何让combobox一获得焦点就显示下拉框??
- 请教:一个错误请帮忙看看,看看如何解决。谢谢
- 求教:把软盘中mdb库中的一个表内容加入到另一个mdb库中,怎样写?
- 关于HINT:如何在Listbox or Listview(ViewStyle:=vsreport)中动态显示每一项目的 Hint ?
================================================
这里找不到答案吗?来这里试试看!
这里有问必答
http://systemer.51.net/cgi-bin/leoboard.cgi
或许你能在这里找到你要的答案
================================================
请接收
IP地址和MAC地址控件
算了,我把源码贴出来吧,不过没有图标噢
} unit yyLib;interfaceuses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, StdCtrls, Graphics, Forms ;const
ycIndent = 5 ;
ycSepWidth = 7 ;
ycDefaultHeight = 20 ;
ycIPLength = 130 ;
ycMACLength = 130 ;type
TMask = 0..32 ;
type //IP
TyyIP = class(TWinControl)
private
{ Private declarations }
FPanel : TPanel ;
FEditIP: array[1..4] of TEdit ;
FLabelSep: array[1..4] of TLabel ;
FEditMask: TEdit ;
FDisplayMask: Boolean ;
FOnChange: TNotifyEvent ;
function TextToIP(S: String): Byte ;
procedure IPKeyPress(Sender: TObject; var Key: Char) ;
procedure IPKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState) ;
procedure MaskKeyPress(Sender: TObject; var Key: Char) ;
procedure MaskKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState) ;
procedure IPChange(Sender: TObject) ;
procedure MaskChange(Sender: TObject) ; procedure DoResize(Sender: TObject) ;
protected
{ Protected declarations }
function GetIP1: Byte ;
procedure SetIP1(Value: Byte) ;
function GetIP2: Byte ;
procedure SetIP2(Value: Byte) ;
function GetIP3: Byte ;
procedure SetIP3(Value: Byte) ;
function GetIP4: Byte ;
procedure SetIP4(Value: Byte) ;
function GetMask: TMask;
procedure SetMask(Value: TMask) ;
function GetDisplayMask: Boolean ;
procedure SetDisplayMask(Value: Boolean) ;
procedure DoChange; dynamic ;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override ;
destructor Destroy; override ;
published
{ Published declarations }
property IP1: Byte read GetIP1 write SetIP1 default 0;
property IP2: Byte read GetIP2 write SetIP2 default 0;
property IP3: Byte read GetIP3 write SetIP3 default 0;
property IP4: Byte read GetIP4 write SetIP4 default 0;
property Mask: TMask read GetMask write SetMask default 24 ;
property DisplayMask: Boolean read GetDisplayMask write SetDisplayMask default False ;
property OnChange: TNotifyEvent read FOnChange write FOnChange ; property AutoSize ;
property Anchors;
property Font ;
property ParentFont ;
property ParentShowHint ;
property ShowHint;
property Visible ;
property OnEnter ;
property OnExit ;
end;type //MAC
TyyMAC = class(TWinControl)
private
{ Private declarations }
FPanel : TPanel ;
FEditMAC: array[1..6] of TEdit ;
FLabelSep: array[1..5] of TLabel ;
FOnChange: TNotifyEvent ;
procedure MACKeyPress(Sender: TObject; var Key: Char) ;
procedure MACKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState) ;
procedure MACChange(Sender: TObject) ;
procedure MACExit(Sender: TObject) ; // 补齐为两位
procedure DoResize(Sender: TObject) ;
protected
{ Protected declarations }
function GetMAC1: String ;
procedure SetMAC1(Value: String) ;
function GetMAC2: String ;
procedure SetMAC2(Value: String) ;
function GetMAC3: String ;
procedure SetMAC3(Value: String) ;
function GetMAC4: String ;
procedure SetMAC4(Value: String) ;
function GetMAC5: String ;
procedure SetMAC5(Value: String) ;
function GetMAC6: String ;
procedure SetMAC6(Value: String) ;
procedure DoChange; dynamic ;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override ;
destructor Destroy; override ;
published
{ Published declarations }
property MAC1: String read GetMAC1 write SetMAC1 ;
property MAC2: String read GetMAC2 write SetMAC2 ;
property MAC3: String read GetMAC3 write SetMAC3 ;
property MAC4: String read GetMAC4 write SetMAC4 ;
property MAC5: String read GetMAC5 write SetMAC5 ;
property MAC6: String read GetMAC6 write SetMAC6 ;
property OnChange: TNotifyEvent read FOnChange write FOnChange ; property AutoSize ;
property Anchors;
property Font ;
property ParentFont ;
property ParentShowHint ;
property ShowHint;
property Visible ;
property OnEnter ;
property OnExit ;
end;
procedure Register;implementation{$R yyLib.dcr}procedure Register;
begin
RegisterComponents('yylib', [TyyIP, TyyMAC]);
end;
var N: Integer ;
begin
//让编辑框只能输入数字
case Ord(Key) of
Ord('0')..Ord('9'): ;//normal
VK_BACK: begin
if ((Sender as TEdit).SelStart = 0) and ((Sender as TEdit).SelLength = 0) then
begin
Key := #0 ;
N := (Sender as TEdit).Tag ;
case N of
2, 3, 4: begin
FEditIP[N - 1].SetFocus ;
FEditIP[N - 1].SelStart := Length(FEditIP[N - 1].Text) ;
FEditIP[N - 1].SelLength:= 0 ;
end ;
else ;
end ; //of case
end ; //of if
end ;
Ord('.'),
Ord('/'): begin //next subip or mask
Key := #0 ;
N := (Sender as TEdit).Tag ;
case N of
1, 2, 3: FEditIP[N + 1].SetFocus ;
else if FEditMask.Visible then
FEditMask.SetFocus ;
end ; //of case
end ;
else Key := #0 ;
end ; //of case
end;procedure TyyIP.IPKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var N: Integer ;
begin
//处理上下左右键,KeyPress事件不支持
case Key of
VK_LEFT,
VK_UP : begin
if ((Sender as TEdit).SelStart = 0) and ((Sender as TEdit).SelLength = 0) then
begin
N := (Sender as TEdit).Tag ;
case N of
2, 3, 4: begin
FEditIP[N - 1].SetFocus ;
FEditIP[N - 1].SelStart := Length(FEditIP[N - 1].Text) ;
FEditIP[N - 1].SelLength:= 0 ;
end ;
else ;
end ; //of case
end ; //of if
end ;
VK_RIGHT,
VK_DOWN : begin
if ((Sender as TEdit).SelStart = Length((Sender as TEdit).Text)) and
((Sender as TEdit).SelLength= 0) then
begin
N := (Sender as TEdit).Tag ;
case N of
1, 2, 3: begin
FEditIP[N + 1].SetFocus ;
FEditIP[N + 1].SelStart := 0 ;
FEditIP[N + 1].SelLength:= 0 ;
end ;
else if FEditMask.Visible then
begin
FEditMask.SetFocus ;
FEditMask.SelStart := 0 ;
FEditMask.SelLength:= 0 ;
end ;
end ; //of case
end ; //of if
end ;
end ; //of case
end;procedure TyyIP.IPChange(Sender: TObject);
var N: Integer ;
begin
with (Sender as TEdit) do
begin
if Text = '' then
begin
Text := '0' ;
DoChange ;
Exit ;
end ; if StrToInt(Text) > 255 then
begin
Beep ;
Text := '255' ;
SetFocus ;
SelStart := 0 ;
SelLength:= 0 ;
end
else if SelStart = MaxLength then //移到下一个控件
begin
N := (Sender as TEdit).Tag ;
case N of
1, 2, 3: if FEditIP[N + 1].Visible then
FEditIP[N + 1].SetFocus
else if FEditMask.Visible then
FEditMask.SetFocus ;
else if FEditMask.Visible then
FEditMask.SetFocus ;
end ; //of case
end ;
end ; //of with
DoChange ;
end;procedure TyyIP.MaskKeyPress(Sender: TObject; var Key: Char) ;
begin
//让编辑框只能输入数字
case Ord(Key) of
Ord('0')..Ord('9'): ; //normal
VK_BACK: begin
if ((Sender as TEdit).SelStart = 0) and ((Sender as TEdit).SelLength = 0) then
begin
Key := #0 ;
FEditIP[4].SetFocus ;
FEditIP[4].SelStart := Length(FEditIP[4].Text) ;
FEditIP[4].SelLength:= 0 ;
end ;
end ;
else Key := #0 ;
end ; //of case
end;procedure TyyIP.MaskKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
case Key of
VK_LEFT,
VK_UP : begin
if ((Sender as TEdit).SelStart = 0) and ((Sender as TEdit).SelLength = 0) then
begin
FEditIP[4].SetFocus ;
FEditIP[4].SelStart := Length(FEditIP[4].Text) ;
FEditIP[4].SelLength:= 0 ;
end ; //of if
end ;
end ; //of case
end;procedure TyyIP.MaskChange(Sender: TObject);
begin
with (Sender as TEdit) do
begin
if Text = '' then
begin
Text := '0' ;
end ; if StrToInt(Text) > 32 then
begin
Text := '32' ;
SelectAll ;
SetFocus ;
end ;
end ; //of with
DoChange ;
end;procedure TyyIP.DoResize(Sender: TObject) ;
var i: Integer ;
EditWidth: Integer ;
begin
FPanel.Width := Width ;
FPanel.Height:= Height; if FDisplayMask then
EditWidth := (Width - ycIndent * 2 - ycSepWidth * 4) div 5
else
EditWidth := (Width - ycIndent * 2 - ycSepWidth * 3) div 4 ; for i := 1 to 4 do
begin
FEditIP[i].Left := ycIndent + (i - 1) * (EditWidth + ycSepWidth) ;
FEditIP[i].Width:= EditWidth;
FEditIP[i].Height := Height ;
FLabelSep[i].Left := ycIndent + EditWidth * i + ycSepWidth * (i - 1) ;
FLabelSep[i].Height:= Height ;
end ; //of for
FEditMask.Left := ycIndent + (EditWidth + ycSepWidth) * 4 ;
FEditMask.Width:= EditWidth ;
FEditMask.Height := Height ;
end;
var i: Integer ;
begin
inherited Create(AOwner) ; Width := ycIPLength ;
Height:= ycDefaultHeight ;
OnResize := DoResize ;
FPanel := TPanel.Create(Self) ;
with FPanel do
begin
Parent := Self ;
Caption := '' ;
Left := 0 ;
Top := 0 ;
Color := clWindow ;
BorderStyle := bsSingle ;
BevelInner := bvNone ;
BevelOuter := bvNone ;
end ; //of with
//用来分隔IP的'.'
for i := 1 to 4 do
begin
FLabelSep[i] := TLabel.Create(Self) ;
with FLabelSep[i] do
begin
Parent := FPanel ;
Top := 3 ;
Width := ycSepWidth ;
Caption:= '.' ;
Alignment := taCenter ;
end ; //of with
end ; //of for
FLabelSep[4].Caption := '/' ;
for i := 1 to 4 do
begin
FEditIP[i] := TEdit.Create(Self) ;
with FEditIP[i] do
begin
Parent := FPanel ;
Top := 2 ;
Text := '0' ;
Tag := i ;
MaxLength := 3 ;
BorderStyle := bsNone ;
BevelInner := bvNone ;
BevelOuter := bvNone ;
OnKeyPress := IPKeyPress ;
OnKeyDown := IPKeyDown ;
OnChange := IPChange ;
end ; //of with
end ; //of for FEditMask := TEdit.Create(Self) ;
with FEditMask do
begin
Parent := FPanel ;
Top := 2 ;
Text := '24' ;
MaxLength := 2 ;
BorderStyle := bsNone ;
BevelInner := bvNone ;
BevelOuter := bvNone ;
OnKeyPress := MaskKeyPress ;
OnKeyDown := MaskKeyDown ;
OnChange := MaskChange ;
end ; //of with FDisplayMask := False ;
SetDisplayMask(FDisplayMask) ;
end;destructor TyyIP.Destroy;
var i: Integer ;
begin
for i := 1 to 4 do
begin
FLabelSep[i].Free ;
FEditIP[i].Free ;
end ; //of for FEditMask.Free ;
FPanel.Free ;
inherited Destroy ;
end;function TyyIP.TextToIP(S: String): Byte;
var N: Integer ;
begin
if not TryStrToInt(S, N) then
Result := 0
else
if N > 255 then
Result := 255
else if N < 0 then
Result := 0
else
Result := N ;
end;function TyyIP.GetIP1: Byte;
begin
Result := TextToIP(FEditIP[1].Text) ;
end;function TyyIP.GetIP2: Byte;
begin
Result := TextToIP(FEditIP[2].Text) ;
end;function TyyIP.GetIP3: Byte;
begin
Result := TextToIP(FEditIP[3].Text) ;
end;function TyyIP.GetIP4: Byte;
begin
Result := TextToIP(FEditIP[4].Text) ;
end;function TyyIP.GetMask: TMask;
var S: String ;
N: Integer ;
begin
S := FEditMask.Text ;
if not TryStrToInt(S, N) then
Result := 0
else
if N > 32 then
Result := 32
else if N < 0 then
Result := 0
else
Result := N ;
end;procedure TyyIP.SetIP1(Value: Byte);
begin
FEditIP[1].Text := IntToStr(Value) ;
DoChange ;
end;procedure TyyIP.SetIP2(Value: Byte);
begin
FEditIP[2].Text := IntToStr(Value) ;
DoChange ;
end;procedure TyyIP.SetIP3(Value: Byte);
begin
FEditIP[3].Text := IntToStr(Value) ;
DoChange ;
end;procedure TyyIP.SetIP4(Value: Byte);
begin
FEditIP[4].Text := IntToStr(Value) ;
DoChange ;
end;procedure TyyIP.SetMask(Value: TMask);
begin
FEditMask.Text := IntToStr(Value) ;
DoChange ;
end;function TyyIP.GetDisplayMask: Boolean;
begin
Result := FDisplayMask ;
end;procedure TyyIP.SetDisplayMask(Value: Boolean);
begin
FDisplayMask := Value ; FLabelSep[4].Visible := FDisplayMask ;
FEditMask.Visible := FDisplayMask ; DoResize(Self) ;
end;procedure TyyIP.DoChange;
begin
if Assigned(FOnChange) then
FOnChange(Self) ;
end;
{ TyyMAC }constructor TyyMAC.Create(AOwner: TComponent);
var i: Integer ;
begin
inherited Create(AOwner) ; Width := ycMACLength ;
Height:= ycDefaultHeight ;
OnResize := DoResize ;
FPanel := TPanel.Create(Self) ;
with FPanel do
begin
Parent := Self ;
Caption := '' ;
Left := 0 ;
Top := 0 ;
Color := clWindow ;
BorderStyle := bsSingle ;
BevelInner := bvNone ;
BevelOuter := bvNone ;
end ; //of with
//用来分隔MAC的'-'
for i := 1 to 5 do
begin
FLabelSep[i] := TLabel.Create(Self) ;
with FLabelSep[i] do
begin
Parent := FPanel ;
Top := 3 ;
Caption:= '-' ;
Alignment := taCenter ;
end ; //of with
end ; //of for
for i := 1 to 6 do
begin
FEditMAC[i] := TEdit.Create(Self) ;
with FEditMAC[i] do
begin
Parent := FPanel ;
Top := 2 ;
Text := '' ;
Tag := i ;
MaxLength := 2 ;
BorderStyle := bsNone ;
BevelInner := bvNone ;
BevelOuter := bvNone ;
OnKeyPress := MACKeyPress ;
OnKeyDown := MACKeyDown ;
OnChange := MACChange ;
OnExit := MACExit ;
end ; //of with
end ; //of for DoResize(Self) ;
end;destructor TyyMAC.Destroy;
var i: Integer ;
begin
for i := 1 to 5 do
begin
FLabelSep[i].Free ;
end ; //of for for i := 1 to 6 do
begin
FEditMAC[i].Free ;
end ; //of for FPanel.Free ;
inherited Destroy ;
end;function TyyMAC.GetMAC1: String;
begin
Result := FEditMAC[1].Text ;
end;function TyyMAC.GetMAC2: String;
begin
Result := FEditMAC[2].Text ;
end;function TyyMAC.GetMAC3: String;
begin
Result := FEditMAC[3].Text ;
end;function TyyMAC.GetMAC4: String;
begin
Result := FEditMAC[4].Text ;
end;function TyyMAC.GetMAC5: String;
begin
Result := FEditMAC[5].Text ;
end;function TyyMAC.GetMAC6: String;
begin
Result := FEditMAC[6].Text ;
end;procedure TyyMAC.MACChange(Sender: TObject);
var N: Integer ;
begin
with (Sender as TEdit) do
begin
if SelStart = MaxLength then //移到下一个控件
begin
N := (Sender as TEdit).Tag ;
case N of
1, 2, 3, 4, 5: FEditMAC[N + 1].SetFocus ;
end ; //of case
end ;
end ; //of with DoChange ;
end;procedure TyyMAC.MACKeyPress(Sender: TObject; var Key: Char);
var N: Integer ;
begin
//让编辑框只能输入数字和'A'..'F'
case Ord(Key) of
Ord('0')..Ord('9'), Ord('A')..Ord('F'): ; //normal
Ord('a')..Ord('f'): Dec(Key, 32) ; //UpperCase
VK_BACK: begin
if ((Sender as TEdit).SelStart = 0) and ((Sender as TEdit).SelLength = 0) then
begin
Key := #0 ;
N := (Sender as TEdit).Tag ;
case N of
2, 3, 4, 5, 6:
begin
FEditMAC[N - 1].SetFocus ;
FEditMAC[N - 1].SelStart := Length(FEditMAC[N - 1].Text) ;
FEditMAC[N - 1].SelLength:= 0 ;
end ;
else ;
end ; //of case
end ; //of if
end ;
Ord('-'): begin //next subip or mask
Key := #0 ;
N := (Sender as TEdit).Tag ;
case N of
1, 2, 3, 4, 5: FEditMAC[N + 1].SetFocus ;
end ; //of case
end ;
else Key := #0 ;
end ; //of case
end;procedure TyyMAC.MACKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var N: Integer ;
begin
//处理上下左右键,KeyPress事件不支持
case Key of
VK_LEFT,
VK_UP : begin
if ((Sender as TEdit).SelStart = 0) and ((Sender as TEdit).SelLength = 0) then
begin
N := (Sender as TEdit).Tag ;
case N of
2, 3, 4, 5, 6:
begin
FEditMAC[N - 1].SetFocus ;
FEditMAC[N - 1].SelStart := Length(FEditMAC[N - 1].Text) ;
FEditMAC[N - 1].SelLength:= 0 ;
end ;
else ;
end ; //of case
end ; //of if
end ;
VK_RIGHT,
VK_DOWN : begin
if ((Sender as TEdit).SelStart = Length((Sender as TEdit).Text)) and
((Sender as TEdit).SelLength= 0) then
begin
N := (Sender as TEdit).Tag ;
case N of
1, 2, 3, 4, 5:
begin
FEditMAC[N + 1].SetFocus ;
FEditMAC[N + 1].SelStart := 0 ;
FEditMAC[N + 1].SelLength:= 0 ;
end ;
end ; //of case
end ; //of if
end ;
end ; //of case
end;procedure TyyMAC.MACExit(Sender: TObject);
begin
with (Sender as TEdit) do
case Length(Text) of
// 0: Text := '00' ;
1: Text := '0' + Text ;
else ;
end ; //of case
DoChange ;
end;procedure TyyMAC.SetMAC1(Value: String);
begin
FEditMAC[1].Text := Copy(Value, 1, 2) ;
DoChange ;
end;procedure TyyMAC.SetMAC2(Value: String);
begin
FEditMAC[2].Text := Copy(Value, 1, 2) ;
DoChange ;
end;procedure TyyMAC.SetMAC3(Value: String);
begin
FEditMAC[3].Text := Copy(Value, 1, 2) ;
DoChange ;
end;procedure TyyMAC.SetMAC4(Value: String);
begin
FEditMAC[4].Text := Copy(Value, 1, 2) ;
DoChange ;
end;procedure TyyMAC.SetMAC5(Value: String);
begin
FEditMAC[5].Text := Copy(Value, 1, 2) ;
DoChange ;
end;procedure TyyMAC.SetMAC6(Value: String);
begin
FEditMAC[6].Text := Copy(Value, 1, 2) ;
DoChange ;
end;procedure TyyMAC.DoChange;
begin
if Assigned(FOnChange) then
FOnChange(Self) ;
end;procedure TyyMAC.DoResize(Sender: TObject);
var i: Integer ;
EditWidth, SepWidth: Integer ;
begin
if AutoSize then Exit ; FPanel.Width := Width ;
FPanel.Height:= Height; SepWidth := (Width - ycIndent * 2) div 17 ;
EditWidth := SepWidth * 2 ; for i := 1 to 5 do
begin
FEditMAC[i].Left := ycIndent + (i - 1) * (EditWidth + SepWidth) ;
FEditMAC[i].Width:= EditWidth;
FEditMAC[i].Height := Height ;
FLabelSep[i].Left := ycIndent + EditWidth * i + SepWidth * (i - 1) ;
FLabelSep[i].Width := SepWidth ;
FLabelSep[i].Height:= Height ;
end ; //of for
FEditMAC[6].Left := ycIndent + (EditWidth + SepWidth) * 5;
FEditMAC[6].Width:= EditWidth ;
FEditMAC[6].Height := Height ;
end;end.
{$R yyLib.dcr}
或者你自己加上图标