한 두어시간동안 만들어 봤습니다.
잘 작동이 될겁니다. 안되는 부분이나, 의문사항 있으면, 계시판에 올려주세요.
폼에는 edit1, label1, button1, pas전체입니다.
----------------------------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
errKey, crtStr:string;
//특정 문자, 숫자, 기호 제거하는 함수 (ID:PARKISU님의 코드)
function ReplaceChar(sSrc, sLookFor, NewString: string ): string;
var
nPos,
nLenLookFor : integer;
begin
nPos := Pos(sLookFor, sSrc);
nLenLookFor := Length(sLookFor);
while(nPos > 0)do
begin
Delete( sSrc, nPos, nLenLookFor );
Insert( NewString, sSrc, nPos );
nPos := Pos( sLookFor, sSrc );
end;
Result := sSrc;
end;
{만일, Edit1.Text에서 콤마를 제거하려면
ReplaceChar(Edit1.Text, ',' ,'');
와 같이 쓰시면 됩니다.}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (key=#8) or (key=#13) or (key=#27) or ((key>#47) and (key<#58)) or ((key>#64) and (key<#91)) or ((key>#96) and (key<#123)) then
else
begin
showMessage('기호입력불가');
errKey:=Key;
crtStr:=ReplaceChar(Edit1.Text, errKey, '');
edit1.text:=''; // 공백
key:=#27; // 공백에서 남은 errKey제거
edit1.text:=crtStr;
edit1.selStart:=Length(crtStr);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:=crtStr;
end;
end.
|