寫一個函數,當你輸入完12個字符後,當exit和KeyDown是,就自動將12個字符中,對應位置中加入空格字符!很簡單的!最簡單的 function returnstr(edit_temp:Tedit):string; var Str_Temp:string; begin Result:= ''; Str_Temp:=edit_temp.Text; edit_temp.Text:=Copy(edit_temp.text,1,2)+' '+ Copy(edit_temp.text,3,2)+' '+Copy(edit_temp.text,5,2)+' '+Copy(edit_temp.text,7,2)+' '+Copy(edit_temp.text,9,2)+' '+Copy(edit_temp.text,11,2); Result:=edit_temp.Text; end;
笨办法 procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if Key = #8 then Exit else if not (Key in ['0'..'9', 'A'..'F', 'a'..'f']) then Key := #0 else if Length(TEdit(Sender).Text) in [2, 5, 8, 11, 14] then begin TEdit(Sender).Text := TEdit(Sender).Text + ' '; TEdit(Sender).SelStart := Length(TEdit(Sender).Text); end;//if end;
function returnstr(edit_temp:Tedit):string;
var Str_Temp:string;
begin
Result:= '';
Str_Temp:=edit_temp.Text;
edit_temp.Text:=Copy(edit_temp.text,1,2)+' '+ Copy(edit_temp.text,3,2)+' '+Copy(edit_temp.text,5,2)+' '+Copy(edit_temp.text,7,2)+' '+Copy(edit_temp.text,9,2)+' '+Copy(edit_temp.text,11,2);
Result:=edit_temp.Text;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #8 then
Exit
else if not (Key in ['0'..'9', 'A'..'F', 'a'..'f']) then
Key := #0
else if Length(TEdit(Sender).Text) in [2, 5, 8, 11, 14] then
begin
TEdit(Sender).Text := TEdit(Sender).Text + ' ';
TEdit(Sender).SelStart := Length(TEdit(Sender).Text);
end;//if
end;