Delphi generates NIC MAC address

Source: Internet
Author: User
Tags decimal to hex

Gadgets for generating MAC addresses:

{*------------------------------------------------generate MAC address @author @version 2015.7.2 2015.10.22 Modified step length is 256, must be 2 n times The square length does not exceed 5 digits-------------------------------------------------}unit frmsavemac;interfaceuses Windows, Messages, Sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, extctrls, Math;type tsavemacform = Class (tfor    m) Edit1:tedit;    Label1:tlabel;    Edit2:tedit;    Edit3:tedit;    Edit4:tedit;    Edit5:tedit;    Edit6:tedit;    Savedialog1:tsavedialog;    Savebutton:tbutton;    Exitbutton:tbutton;    Edit7:tedit;    Label2:tlabel;    Label3:tlabel;    Edit8:tedit;    Memo1:tmemo;    Groupbox1:tgroupbox;    Radiobutton1:tradiobutton;    Radiobutton2:tradiobutton;    Radiobutton3:tradiobutton;    Btn_clear:tbutton;    Btn_show:tbutton;    Memo2:tmemo;    Procedure edit1keypress (Sender:tobject; var key:char);    Procedure Exitbuttonclick (Sender:tobject);      Procedure Edit1keydown (Sender:tobject; var Key:word; Shift: Tshiftstate);    Procedure edit7keypress (Sender:tobject; var key:char);    Procedure Formcreate (Sender:tobject);    Procedure Savebuttonclick (Sender:tobject);      Procedure Edit1keyup (Sender:tobject; var Key:word;    Shift:tshiftstate);    Procedure Btn_clearclick (Sender:tobject);  Procedure Btn_showclick (Sender:tobject);    Private {Private declarations} procedure Checkisempty;    function Checksteporlen:boolean;    Procedure ShowData ();  Procedure SaveData (); Public {public declarations} End;var savemacform:tsavemacform;implementation{$R *.dfm}{*-------------------------- ----------------------text box can only enter hexadecimal numbers, delete keys, and enter @param @param-------------------------------------------------} Procedure tsavemacform.edit1keypress (Sender:tobject; var key:char); Begin if not (Key in [' 0 ' ... ') 9 ', ' A ' ... ' F ', ' a '.. '    F ', #8, #13]) THEN BEGIN Key: = #0;  Application.messagebox (' only enter hexadecimal digits! ', ' hint message ', MB_OK + mb_iconerror); End;end;procedure TSAVEMACFORM.EXITBUTTONCLICK (sender:tobject); begin close;end; {*------------------------------------------------text box key event @param @ Param-------------------------------------------------}procedure tsavemacform.edit1keydown (Sender:tobject; var)  Key:word; Shift:tshiftstate) var i,j:integer;begin///input maximum length for I: = 0 to self. ComponentCount-1 do begin//loop each edit control is set to a maximum length of 2 2015.10.22 modified if self. Components[i] is Tedit then BEGIN (self. Components[i] as Tedit).    MaxLength: = 2;    End    If Sender = Edit7 then edit7.maxlength: = 3;       If Sender = Edit8 then edit8.maxlength: = 5;  Length not exceeding 5 digits 2015.10.22 modification end; Move the cursor to the last for J: = 0 to ComponentCount-1 does begin if COMPONENTS[J] is Tedit then BEGIN (Components[j] as TEdi T). SelStart: = Length ((Components[j] as Tedit).    Text);  End  End    Press ENTER to trigger if key = and begin if (sender = Edit1) and (Length (Edit1.text) >= 2) then Edit2.setfocus; if (Sender = Edit2) and (Length (Edit2.text) >= 2) then EDIT3.SEtfocus;    if (Sender = Edit3) and (Length (Edit3.text) >= 2) then Edit4.setfocus;    if (Sender = EDIT4) and (Length (Edit4.text) >= 2) then Edit5.setfocus;    if (Sender = Edit5) and (Length (Edit5.text) >= 2) then Edit6.setfocus;    if (Sender = Edit6) then Edit7.setfocus;  if (Sender = Edit7) then Edit8.setfocus;  End  exitbutton.enabled: = True; savebutton.enabled: = True;end; {*------------------------------------------------step can only enter a number from 0 to 9 @param @ Param-------------------------------------------------}procedure tsavemacform.edit7keypress (Sender:tobject; var) KEY:CHAR); Begin if not (key in [' 0 ' ... ')  9 ', #8]) then Key: = #0; end;procedure tsavemacform.formcreate (Sender:tobject); var J:integer;  C:double;begin savebutton.enabled: = False;  exitbutton.enabled: = False;    radiobutton1.checked: = True; The default output format is Memo2.  Lines.add (' n ' of 2 within ' 256: ');         For J: = 1 to 8 do begin C: = Power (2, J); 2 i-th square memo2. Lines.add (Floattostr (C)); End;end;procedure Tsavemacform.checkisempty;begin if (edit1.text = ") or (Edit2.text =") or (Edit3.text = ") or (Edit 4.Text = ") or (Edit5.text =") or (Edit6.text = ") THEN begin Application.messagebox (' input box must be 12 16 binary number! ') ', ' hint ', mb_    OK + mb_iconstop);  Exit  End if (length (Edit1.text) < 2) or (length (Edit1.text) < 2) or (length (Edit1.text) < 2) or (length (Edit1.text) < 2 ) or (Length (Edit1.text) < 2) or (length (Edit1.text) < 2) THEN begin Application.messagebox (' Each input box must be 2 digits! ', ' hint    ', MB_OK + mb_iconerror);  Exit  End if (Edit7.text = ") THEN begin Application.messagebox (' Step cannot be empty!)    ', ' hint ', MB_OK);    Edit7.setfocus;  Exit  End if (Edit8.text = ") THEN begin Application.messagebox (' length cannot be empty!    ', ' hint ', MB_OK);    Edit8.setfocus;  Exit  End;end;function Tsavemacform.checksteporlen:boolean;var Step, L, code, J:integer;  Isnot:boolean;   C:extended;begin Result: = False; If Edit7.text <> "then BEGIN//2015/10/24 added, not previously judged, if empty, there will be a system error step: = Strtoint (Edit7.text);    L: = Strtoint (Edit8.text);      If step > then BEGIN Application.messagebox (' max step length is 256, re-enter! ', ' hint ', MB_OK);      Edit7.setfocus;    Exit  End  End    Judge the length if L >= 100000 then begin Application.messagebox (' length too long, please reenter! ', ' hint ', MB_OK);    Edit8.setfocus;  Exit  End         For J: = 1 to 8 do begin C: = Power (2, J);    2 I-th if (step = C) or (step = 1) THEN BEGIN result: = True;  End   End     Determines whether the step satisfies the condition if result = False then BEGIN Application.messagebox (' step can only be 2 n times, re-enter ', ' hint message ', MB_OK + mb_iconerror);    Edit7.setfocus;  Exit End;end;procedure Tsavemacform.btn_showclick (sender:tobject); begin ShowData (); End;procedure Tsavemacform.showdata  ; var savefile:string;  Value:integer;  Temp, s:string;  I, M1, M2, M3, M4, M5, M6, J:integer;      C:extended;begin Checkisempty;    Determines whether the null if Checksteporlen = True then BEGIN Self.Memo1.Lines.Clear; M1: = STRTOint (' $ ' + edit1.text);    Directly convert the data in the edit into 16 binary (is by decimal to hex) M2: = Strtoint (' $ ' + edit2.text);    M3: = Strtoint (' $ ' + edit3.text);    M4: = Strtoint (' $ ' + edit4.text);    M5: = Strtoint (' $ ' + edit5.text);    M6: = Strtoint (' $ ' + edit6.text); If Radiobutton1.checked then Self.Memo1.Lines.Add (Inttohex (M1, 2) + Inttohex (M2, 2) + Inttohex (M3, 2) + Inttohex (M4,    2) + Inttohex (M5, 2) + Inttohex (M6, 2)); hexadecimal to decimal if radiobutton2.checked then Self.Memo1.Lines.Add (Inttohex (M1, 2) + Inttohex (M2, 2) + Inttohex (M3,    2) + ': ' + Inttohex (M4, 2) + Inttohex (M5, 2) + Inttohex (M6, 2)); If Radiobutton3.checked then Self.Memo1.Lines.Add (Inttohex (M1, 2) + '-' + Inttohex (M2, 2) + '-' +inttohex (M3, 2) + '-    ' + Inttohex (M4, 2) + '-' + Inttohex (M5, 2) + '-' + Inttohex (M6, 2));      For I: = 1 to Strtoint (edit8.text) does begin temp: = ' 0 ';    If M6 < then///less than F, add a 0 begin M6: = Strtoint (' $ ' + inttostr (M6));    M6: = Strtoint (temp + inttohex (M6, 2));      End        If M5 < THEN BEGIN M5: = Strtoint (' $ ' + inttostr (M5));      M5: = Strtoint (temp + inttohex (M5, 2));      End        If M4 < THEN BEGIN M4: = Strtoint (' $ ' + inttostr (M4));      M4: = Strtoint (temp + inttohex (M4, 2));      End        If M3 < THEN BEGIN M3: = Strtoint (' $ ' + inttostr (M3));      M3: = Strtoint (temp + inttohex (M3, 2));      End        If M2 < THEN BEGIN M2: = Strtoint (' $ ' + inttostr (M2));      M2: = Strtoint (temp + inttohex (M2, 2));      End        If M1 < THEN BEGIN M1: = Strtoint (' $ ' + inttostr (M1));      M1: = Strtoint (temp + INTTOHEX (M1, 2));      End              M6: = M6 + strtoint (edit7.text);        Add step if M6 >= and/or if greater than or equal to FF carry begin M5: = M5 + 1;      M6: = m6-256;      End        If M5 >= then begin M4: = M4 + 1; M5: = m5-256;      End        If M4 >= then begin M3: = M3 + 1;      M4: = m4-256;      End        If M3 >= then begin M2: = M2 + 1;      M3: = m3-256;      End        If M2 >= then begin M1: = M1 + 1;      M2: = m2-256;      End      If M1 >= and then Application.messagebox (' out of range ', ' hint message ', MB_OK + mb_iconerror); If Radiobutton1.checked then Self.Memo1.Lines.Add (Inttohex (M1, 2) + Inttohex (M2, 2) + Inttohex (M3, 2) + Inttohex (M4      , 2) + Inttohex (M5, 2) + Inttohex (M6, 2)); If Radiobutton2.checked then Self.Memo1.Lines.Add (Inttohex (M1, 2) + Inttohex (M2, 2) + Inttohex (M3, 2) + ': ' + Intto      Hex (M4, 2) + Inttohex (M5, 2) + Inttohex (M6, 2)); If Radiobutton3.checked then Self.Memo1.Lines.Add (Inttohex (M1, 2) + '-' + Inttohex (M2, 2) + '-' +inttohex (M3, 2) +    '-' + Inttohex (M4, 2) + '-' + Inttohex (M5, 2) + '-' + Inttohex (M6, 2)); End End;end;procedure Tsavemacform.savedata;var Savefile:string;begin if Checksteporlen = True THEN BEGIN//save Savedialog1.filter: = ' *.txt|*.txt ';     ' Txtfile (*.txt) |*.txt ';                                   TXT format savedialog1.defaultext: = ' *.txt ';    Default format savedialog1.title: = ' Save MAC address ';      If Savedialog1.execute then begin SaveFile: = Savedialog1.filename;                                  Memo1.Lines.SaveToFile (SaveFile);  Save data end in memo; End;end;procedure Tsavemacform.savebuttonclick (sender:tobject); begin ShowData (); end;procedure  Tsavemacform.edit1keyup (Sender:tobject; var Key:word;  shift:tshiftstate); var i:integer;begin if Length (edit1.text) >= 2 then Edit2.setfocus;  If Length (edit2.text) >= 2 then Edit3.setfocus;  If Length (edit3.text) >= 2 then Edit4.setfocus;  If Length (edit4.text) >= 2 then Edit5.setfocus; If Length (edit5.text) >= 2 then Edit6.setfocus; (* for I: = 0 to ComponentCount-1 does begin if components[i] is Tedit then if Length (ComponentS[i] as Tedit). Text) >= 2 then end;*) end;procedure Tsavemacform.btn_clearclick (sender:tobject), Var i:integer;begin for I: = 0 To Self.componentcount-1 do BEGIN if self.components[i] was tedit then BEGIN (Self.components[i] as Tedit).    Text: = ';  End  End Edit1.setfocus;end;end.

Delphi generates NIC MAC address

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.