IP地址控件?(100分)

  • 主题发起人 主题发起人 bamfk1023
  • 开始时间 开始时间
B

bamfk1023

Unregistered / Unconfirmed
GUEST, unregistred user!
DELPHI到底有没有自带的IP地址输入的控件?
IPADDRESS是自已定义的吗?如果使用。
还有大家所说的IPEDIT都用得不怎么理想?
求好一点的解决方案。
 
谁有没有完整一点的。
下载的三四个都不行。可能是很多的uses 中的pas没有 或找不到或在Delphi6中更名了
我是用在DELPHI6的。每次安装都有错误。怎么办!!!
烦ing //////////
 
Delphi 7 中 Indy Misc 控件组中有一个TIdIpWatch控件,
用这个属性 IdIPWatch1.LocalIP 可以取出 IP ,在Delphi 6中不知道有没有,没用过。
 
DELPHI6也有IdIPWatch(我下载了indy9),不过不是输入界面,
只是有一个返回本机IP地址的属性。
不像WINDOW的IP设置的输入框。
 
IP地址控件是IE4自带的,只是Delphi没有把他封装
 
关键是有什么方法把IE4的地址控件封并装到DELPHI中来?
 
ip地址控件就没有啦。给你语句,也可以捞点分了吧!不过自己做这样的控件,好象不是很难。
var
ch: array[1..32] of Char;
i: integer;
str:string;
WSData: TWSAData;
MyHost: PHostEnt;
begin
////////*****************得到本机IP***************************
if WSAstartup(2, wsdata) <> 0 then
begin
//Writeln('can''t start Winsock: Error ', WSAGetLastError);
//Halt(2);
end;
MyHost := GetHostByName(@ch[1]);
if MyHost <> nil then
for i := 1 to 4 do
begin
// ServerSocket1.Port:=strtoint('1'+(inttostr(Ord(MyHost.h_addr^[4 - 1]))));
str:= str+ inttostr(Ord(MyHost.h_addr^[i - 1]));
if i < 4 then
str:= str+ '.'
end;
////////*****************end得到本机IP***************************
 
我有第三方的VCL,保证可用。
 
你是要输入IP地址的控件吗?我有一个,要就给个地址吧
 
我想要
xf-wangyi@163.com

 
unit IPEdit;

interface

uses Windows, Messages, SysUtils, Classes, Forms, Controls, ComCtrls, CommCtrl;

type
TFieldRange = record
LowRange: Byte;
HighRange: Byte;
end;

TFieldChangeEvent = procedure(Sender: TObject;OldField, Value: Byte) of Object;

TIPEdit = class(TWinControl)
private
FIP: LongWord;
FFields:array[0..3] of Byte;
FFieldRanges: array [0..3] of TFieldRange;
FCreating: Boolean;
FOnChange: TNotifyEvent;
FOnEnter: TNotifyEvent;
FOnExit: TNotifyEvent;
FOnFieldChange: TFieldChangeEvent;
procedure SetIP(Value: LongWord);
function GetIP: LongWord;
function GetField(Index:Integer):Byte;
procedure SetField(Index:Integer; B:Byte);
function GetFieldRange(Field: Integer):TFieldRange;
procedure SetFieldRange(Field:integer; Value:TFieldRange);
procedure SetIPAddress;
function GetBlank: Boolean;
procedure WMNotifyFormat(var Message: TMessage);message WM_NOTIFYFORMAT;
procedure CNNotify(var Message: TWMNotify);message CN_NOTIFY;
procedure CNCommand(var Message: TWMCommand);message CN_COMMAND;
procedure WMSetFont(var Message: TWMSetFont);message WM_SETFONT;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Clear;
procedure SetFieldFocus(Field:Byte);
published
property Blank: Boolean read GetBlank;
property Field0: Byte index 0 read GetField write SetField;
property Field1: Byte index 1 read GetField write SetField;
property Field2: Byte index 2 read GetField write SetField;
property Field3: Byte index 3 read GetField write SetField;
property Field0Range: TFieldRange index 0 read GetFieldRange write SetFieldRange;
property Field1Range: TFieldRange index 1 read GetFieldRange write SetFieldRange;
property Field2Range: TFieldRange index 2 read GetFieldRange write SetFieldRange;
property Field3Range: TFieldRange index 3 read GetFieldRange write SetFieldRange;
property IP: LongWord read GetIP write SetIP;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnEnter: TNotifyEvent read FOnEnter write FOnEnter;
property OnExit: TNotifyEvent read FOnExit write FOnExit;
property OnFieldChange: TFieldChangeEvent read FOnFieldChange write FOnFieldChange;
property Enabled;
property TabOrder;
property TabStop;
property ParentShowHint;
property ShowHint;
property Hint;
property Visible;
end;

procedure Register;

implementation

constructor TIPEdit.Create(AOwner: TComponent);
var
i: integer;
begin
CheckCommonControl(ICC_INTERNET_CLASSES);
inherited Create(AOwner);
for i:= 0 to 3 do
begin
FFieldRanges.LowRange:= 0;
FFieldRanges.HighRange:= 255;
FFields:=0;
end;
FIP:=0;
Height:= 25;
Width:= 152;
TabSTop:= True;
end;

procedure TIPEdit.DestroyWnd;
begin
inherited DestroyWnd;
end;

destructor TIPEdit.Destroy;
begin
inherited Destroy;
end;

procedure TIPEdit.CreateParams(var Params:
TCreateParams);
begin
inherited CreateParams(Params);
CreateSubClass(Params, WC_IPADDRESS);
end;

procedure TIPEdit.CreateWnd;
begin
FCreating := True;
try
inherited CreateWnd;
SetIPAddress;
finally
FCreating := False;
end;
end;

function TIPEdit.GetBlank: Boolean;
begin
Result:= Boolean(SendMessage(Handle, IPM_ISBLANK, 0, 0));
end;

procedure TIPEdit.Clear;
begin
SendMessage(Handle, IPM_CLEARADDRESS, 0, 0);
end;

procedure TIPEdit.SetFieldFocus(Field:Byte);
begin
SendMessage(Handle, IPM_SETFOCUS, Field, 0);
end;

function TIPEdit.GetFieldRange(Field: Integer): TFieldRange;
begin
Result:= FFieldRanges[Field];
end;

procedure TIPEdit.SetFieldRange(Field: Integer;
Value: TFieldRange);
begin
if Value.LowRange > Value.HighRange then exit;
if (FFieldRanges[Field].LowRange <> Value.LowRange) or
(FFieldRanges[Field].HighRange <> Value.HighRange) then
begin
FFieldRanges[Field]:= Value;
SendMessage(Handle, IPM_SETRANGE, Field,
MakeIPRange(Value.LowRange, Value.HighRange));
end;
end;

function TIPEdit.GetField(Index: Integer): Byte;
begin
if (Index>=0)and(Index<=3) then Result:=FFields[Index]
else Result:=0;
end;

procedure TIPEdit.SetField(Index:Integer; B:Byte);
begin
if (FFields[Index] <> B)then
begin
FFields[Index]:=B;
SetIPAddress;
end;
end;

procedure TIPEdit.SetIPAddress;
var
i:LongWord;
begin
i:=MAKEIPADDRESS(FFields[0], FFields[1], FFields[2],FFields[3]);
SendMessage(Handle, IPM_SETADDRESS, 0, i);
FIP:=i;
end;

procedure TIPEdit.SetIP(Value: LongWord);
begin
if (FIP <> Value) then
begin
FFields[0]:= First_IPAddress(Value);
FFields[1]:= Second_IPAddress(Value);
FFields[2]:= Third_IPAddress(Value);
FFields[3]:= Fourth_IPAddress(Value);
SetIPAddress;
end;
end;

function TIPEdit.GetIP: LongWord;
begin
SendMessage(Handle, IPM_GETADDRESS, 0,Integer(@Result));
end;

procedure TIPEdit.WMSetFont(var Message: TWMSetFont);
begin
//
end;

procedure TIPEdit.WMNotifyFormat(var Message:
TMessage);
begin
with Message do
Result := DefWindowProc(Handle, Msg, WParam, LParam);
end;

procedure TIPEdit.CNNotify(var Message: TWMNotify);
var
pNM: PNMIPAddress;
begin
with (Message.NMHdr)^ do
begin
case Code of
IPN_FIELDCHANGED:
begin
pNM:=PNMIPADDRESS(Message.NMHdr);
if (pNM^.iField>=0)and(pNM^.iField<=3) then
FFields[pNM^.iField]:=pNM^.iValue;
if Assigned(FOnFieldChange) then
FOnFieldChange(self, pNM^.iField, pNM^.iValue);
end;
end;
end;
end;

procedure TIPEdit.CNCommand(var Message: TWMCommand);
begin
case Message.NotifyCode of
EN_CHANGE:
begin
if not FCreating then
if Assigned(FOnChange) then FOnChange(self);
end;
EN_KILLFOCUS: if Assigned(FOnExit) then FOnExit(self);
EN_SETFOCUS: if Assigned(FOnEnter) then FOnEnter(self);
end;
end;

procedure Register;
begin
RegisterComponents('Samples', [TIPEdit]);
end;

end.
 
不错,不过我还要改进改进,呵呵

改成平面的,因为我有一个程序中全是平面的

唉,还得加一个方法,好一次把我要的IP地址取出来
好像192.168.001.005
这样的才行,加齐三位
 
我也要
china-e-boy@163.net
不胜感激
 
让人不是很满意 1、背景为什么是白色的 2、放大一下里面的四个值不会一起放大
 
{请大家看一下我现在用的}
unit IPEdit;

{ This is a simple IP Address Editor component. Many traditional TEdit Methots/Properties
are supported. One major difference is the 'Value' property which gives the CARDINAL value
of a TCP/IP address (192.168.1.1 becomes $C0A80101 or 3232235777). This makes to/from range
enty a snap.
Modelled by bhoc@surfeu.ch.
This is GPL Code.
}

// 荐沥磊 : 冠沥葛
// 荐沥老 : 2002.3.19
// 荐沥郴侩 : 菩澄困俊 乐绰 Edit 埃阑 拳混虐肺 捞悼且 荐 乐档废 茄促
// - KeyDown procedure 甫 override秦辑 父甸绢 脸促

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;

type
jIPEdit = class;

jIPByteEdit = class( TEdit )
private
MyAlignment : TAlignment;
procedure SetAlignment(Value: TAlignment);

protected
procedure Change; override;
procedure CreateParams( var Params : TCreateParams ); override;
procedure KeyDown( var Key : Word; Shift : TShiftState ); override;

public

published
ParentPanel : jIPEdit;

constructor Create( AOwner : TComponent ); override;

property Alignment : TAlignment read MyAlignment write SetAlignment;

end;

jIPEdit = class( TCustomPanel )
private
{ Private declarations }
MyEnabled : Boolean;
InternalMove : Boolean;

MyChange : TNotifyEvent;
MyEnter : TNotifyEvent;

procedure PanelEnter( Sender : TObject );
procedure MyResize( Sender : TObject );
procedure PanelClick( Sender : TObject );
procedure PanelDblClick( Sender : TObject );
procedure FilterKey( Sender : TObject; var Key : Char );
procedure ExitByteEdit( Sender : TObject );
procedure EditClick( Sender : TObject );
procedure EditChange( Sender : TObject );

function GetText : String;
function GetValue : Cardinal;
function GetValueParts( piIndex : Integer ) : Integer;

procedure SetText( Value : String );
procedure SetValue( Value : Cardinal );
procedure Set_Enabled( Value : Boolean );
procedure SetValueParts( piIndex : Integer; const Value : Integer );

protected
IPByteEdit : array [ 0..3 ] of jIPByteEdit;
Dots : array [ 0..3 ] of TLabel;

public
property ValueParts[ piIndex : Integer ] : Integer read GetValueParts write SetValueParts;

constructor Create( AOwner : TComponent ); override;
destructor Destroy; override;

procedure Loaded; override;

published
property Anchors;
property BorderStyle;
property Color;
property Ctl3D stored TRUE;
property Enabled : boolean read MyEnabled write Set_Enabled;
property Font;
property ShowHint;
property TabOrder;
property TabStop;
property Text : String read GetText write SetText stored TRUE;
property Value : Cardinal read GetValue write SetValue stored TRUE;
property Visible;

property OnChange : TNotifyEvent read MyChange write MyChange;
property OnClick;
property OnDblClick;
property OnEnter : TNotifyEvent read MyEnter write MyEnter;
property OnExit;

end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents( 'NetCruz', [ jIPEdit ] );
end;

{ jIPByteEdit }

procedure jIPByteEdit.Change;
begin
inherited;

if ( ( Length( Text ) = 3 ) AND
( SelStart = Length( Text ) ) ) AND
( ( Tag = 0 ) OR
( Tag = 1 ) OR
( Tag = 2 ) ) then
with jIPEdit( Parent ).IPByteEdit[ Tag + 1 ] do
begin
SetFocus;
SelStart := 0;
SelLength := Length( Text );
end;
end;

constructor jIPByteEdit.Create( AOwner : TComponent );
begin
inherited Create( AOwner );

Alignment := taCenter;
BorderStyle := bsNone;
Text := '0';
end;

procedure jIPByteEdit.CreateParams( var Params : TCreateParams );
begin
inherited CreateParams( Params );

case Alignment of
taLeftJustify : Params.Style := Params.Style or ES_LEFT and Not ES_MULTILINE;
taRightJustify : Params.Style := Params.Style or ES_RIGHT and Not ES_MULTILINE;
taCenter : Params.Style := Params.Style or ES_CENTER and Not ES_MULTILINE;
end;
end;

procedure jIPByteEdit.KeyDown( var Key : Word; Shift : TShiftState );
begin
if Parent is jIPEdit then
case Key of
VK_LEFT :
if ( SelStart = 0 ) AND
( ( Tag = 1 ) OR
( Tag = 2 ) OR
( Tag = 3 ) ) then
jIPEdit( Parent ).IPByteEdit[ Tag - 1 ].SetFocus;

VK_RIGHT :
if ( SelStart = Length( Text ) ) AND
( ( Tag = 0 ) OR
( Tag = 1 ) OR
( Tag = 2 ) ) then
jIPEdit( Parent ).IPByteEdit[ Tag + 1 ].SetFocus;

// BackSpace狼 悼累 炼扒
// - SelText啊 乐促 -> Default悼累
// - SelText啊 绝促 & Carrot捞 霉锅掳俊 乐促 -> 捞傈 Edit俊 目辑 傈崔 & VK_BACK 皋矫隆
VK_BACK :
if ( ( SelText = '' ) AND
( SelStart = 0 ) ) AND
( ( Tag = 1 ) OR
( Tag = 2 ) OR
( Tag = 3 ) ) then
with jIPEdit( Parent ).IPByteEdit[ Tag - 1 ] do
begin
SetFocus;
SelStart := Length( Text );

if Text <> '' then
PostMessage( Handle, WM_KEYDOWN, VK_BACK, 0 );
end;

VK_HOME :
with jIPEdit( Parent ).IPByteEdit[ 0 ] do
begin
SetFocus;
SelStart := 0;
end;

VK_END :
with jIPEdit( Parent ).IPByteEdit[ 3 ] do
begin
SetFocus;
SelStart := Length( Text );
end;
end;

inherited;
end;

procedure jIPByteEdit.SetAlignment(Value: TAlignment);
begin
if MyAlignment <> Value then
begin
MyAlignment := Value;
RecreateWnd;
end;
end;

{ jIPEdit }

procedure jIPEdit.Loaded;
begin
inherited loaded;
MyResize( Self ); // 哪器惩飘啊 肺爹登搁 阿 Editor狼 农扁甫 促矫 炼沥茄促
end;

destructor jIPEdit.Destroy;
var
i : Integer;
begin
for i := 0 to 3 do
begin
IPByteEdit[ i ].Free;
Dots[ i ].Free;
end;

inherited Destroy;
end;

constructor jIPEdit.Create( AOwner : TComponent );
var
i : Integer;
begin
inherited Create( AOwner );
inherited Enabled := TRUE;
inherited OnEnter := PanelEnter;

OnEnter := nil;
OnChange := nil;
MyEnabled := TRUE;
Caption := ''; // 菩澄 母记 力芭
Height := 21; // 钎霖农扁
InternalMove := False;
BevelInner := bvNone;
BevelOuter := bvNone;
BorderStyle := bsSingle;
OnResize := MyResize; // 菩澄救俊 甸绢 乐绰 Edit狼 农扁 磊悼拳
Color := clWindow;

// 菩澄困狼 Edit客 Label阑 积己茄促
for i := 0 to 3 do
begin
IPByteEdit[ i ] := jIPByteEdit.Create( Self );
with IPByteEdit[ i ] do
begin
AutoSelect := FALSE;
Parent := Self;
Tag := i;
MaxLength := 3;
ParentColor := TRUE;
ParentFont := TRUE;
ParentShowHint := TRUE;

OnKeyPress := FilterKey;
OnExit := ExitByteEdit;
OnClick := EditClick;
OnDblClick := PanelDblClick;
OnChange := EditChange;
end;

Dots[ i ] := TLabel.Create( Self );
with Dots[ i ] do
begin
AutoSize := TRUE;
Alignment := taCenter;
Parent := Self;
ParentColor := TRUE;
ParentFont := TRUE;
ParentShowHint := TRUE;

OnClick := PanelClick;
OnDblClick := PanelDblClick;
Caption := '.';
end;
end;

Dots[ 3 ].Caption := '';
Dots[ 3 ].Visible := False;
end;

procedure jIPEdit.PanelEnter( Sender : TObject );
begin
// 菩澄俊 器目胶啊 甸绢坷搁 霉锅掳 Edit 俊 器目胶甫 傈崔
IPByteEdit[ 0 ].SetFocus;

if Assigned( OnEnter ) then
OnEnter( Self );
end;

procedure jIPEdit.EditClick( Sender : TObject );
begin
if InternalMove = TRUE then
InternalMove := FALSE
else if Assigned( inherited OnClick ) then
OnClick( Self );
end;

procedure jIPEdit.EditChange( Sender : TObject );
begin
if Assigned( OnChange ) then
OnChange( Self );
end;

procedure jIPEdit.PanelClick( Sender : TObject );
begin
if Assigned( inherited OnClick ) then
OnClick( Self );
end;

procedure jIPEdit.PanelDblClick( Sender : TObject );
begin
if Assigned( inherited OnDblClick ) then
OnDblClick( Self );
end;

procedure jIPEdit.FilterKey( Sender : TObject; var Key : Char );
var
i : Integer;
begin
if Sender is jIPByteEdit then // 阿 Edit肺 何磐 虐啊 傈崔登菌促
case Key of
'.':
begin
i := jIPByteEdit( Sender ).Tag;
Key := #0;

case i of
0..2 :
begin
InternalMove := TRUE;

with IPByteEdit[ i + 1 ] do
begin
SetFocus;
SelStart := 0;
SelLength := Length( Text );
end;
end;
end;
end;

'0'..'9', #8: // do nothing special

else
Key := #0;
end;
end;

procedure jIPEdit.Set_Enabled( Value : Boolean );
var
i : Integer;
begin
inherited Enabled := Value;

MyEnabled := Value;
for i := 0 to 3 do
begin
IPByteEdit[ i ].Enabled := Value;
Dots[ i ].Enabled := Value;
end;
end;

procedure jIPEdit.ExitByteEdit( Sender : TObject );
begin
if Sender is jIPByteEdit then
with jIPByteEdit( Sender ) do
begin
if Trim( Text ) = '' then
EXIT;

try
Text := IntToStr( StrToInt( Text ) mod 256 );
except
end;
end;
end;

function jIPEdit.GetText : String;
begin
Result := IPByteEdit[ 0 ].Text + '.' +
IPByteEdit[ 1 ].Text + '.' +
IPByteEdit[ 2 ].Text + '.' +
IPByteEdit[ 3 ].Text;
end;

Procedure jIPEdit.SetText( Value : String );
var
i,
liPos : Integer;

function Mod256( sByte : String ) : String;
begin
try
Result := IntToStr( StrToInt( sByte ) mod 256 );
except
Result := '';
end;
end;

begin
Value := Trim( Value ) + '.';

liPos := Pos( '.', Value );

// 巩磊凯阑 瞒肥肺 Edit俊 傈崔茄促
i := 0;
while liPos > 0 do
begin
IPByteEdit[ i ].Text := Mod256( Copy( Value, 1, liPos - 1 ) );

Inc( i );
if i > 3 then
EXIT;

Value := Copy( Value, liPos + 1, Length( Value ) - liPos );
liPos := Pos( '.', Value );
end;
end;

function jIPEdit.GetValue : Cardinal;
var
liFirst,
liSecond,
liThird,
liFourth : Integer;
begin
try
liFirst := StrToInt( IPByteEdit[ 0 ].Text );
except
liFirst := 0;
end;

try
liSecond := StrToInt( IPByteEdit[ 1 ].Text );
except
liSecond := 0;
end;

try
liThird := StrToInt( IPByteEdit[ 2 ].Text );
except
liThird := 0;
end;

try
liFourth := StrToInt( IPByteEdit[ 3 ].Text );
except
liFourth := 0;
end;

Result := ( liFirst shl 24 ) or
( liSecond shl 16 ) or
( liThird shl 8 ) or
liFourth;
end;

procedure jIPEdit.SetValue( Value : Cardinal );
var
i : Integer;
begin
if Value = 0 then
for i := 3 downto 0 do
IPByteEdit[ i ].Text := ''

else
for i := 3 downto 0 do
begin
IPByteEdit[ i ].Text := IntToStr( Value and $FF );
Value := Value shr 8;
end;
end;

// 窃荐 : MyResize
// 扁瓷 : Panel困俊 乐绰 匙俺狼 Edit客 Label阑 舅嘎篮 困摹肺 汲沥茄促
procedure jIPEdit.MyResize( Sender : TObject );
var
i,
dw,
ew,
ewMin,
hMin,
TotWidth,
BorderWidth : Integer;
begin
BorderWidth := Width - ClientWidth;
ewMin := Dots[ 0 ].Canvas.TextWidth ( '000' );
hMin := Dots[ 0 ].Canvas.TextHeight( '0' );
dw := Dots[ 0 ].Width;
ew := ( Width - BorderWidth - dw - dw - dw ) div 4;

if ew < ewMin then
ew := ewMin;

TotWidth := ew + ew + ew + ew + dw + dw + dw + BorderWidth;
if Height < ( hMin + BorderWidth ) then
Height := hMin + BorderWidth

else if Width < TotWidth then
Width := TotWidth

else
for i := 0 to 3 do
begin
with IPByteEdit[ i ] do
begin
Width := ew;
Height := hMin;
Left := i * ( ew + dw );
Top := ( Self.ClientHeight - hMin ) div 2;
end;

with Dots[ i ] do
begin
Height := IPByteEdit[ i ].Height;
Top := IPByteEdit[ i ].Top;
Left := ew + i * ( ew + dw );
end;
end;
end;

function jIPEdit.GetValueParts( piIndex : Integer ) : Integer;
begin
Result := 0;

if ( piIndex < 0 ) OR
( piIndex > 3 ) then
EXIT;

try
Result := StrToInt( IPByteEdit[ piIndex ].Text );
except
Result := 0;
end;
end;

procedure jIPEdit.SetValueParts( piIndex : Integer; const Value : Integer );
begin
if ( piIndex < 0 ) OR
( piIndex > 3 ) then
EXIT;

IPByteEdit[ piIndex ].Text := IntToStr( Value mod 256 );
end;

end.


 
人多了。
平均分配好了
 
我想要一个现成的IP地址输入控件,给我发一个好吗?谢谢!xtjf@163.net
 
后退
顶部