Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[7088] [답변] PETIPRIN/ Edit에 특정키가 입력되지 않으려면..
k2453540 [ ] 654 읽음    2000-03-13 19:35

한 두어시간동안 만들어 봤습니다.
잘 작동이 될겁니다. 안되는 부분이나, 의문사항 있으면, 계시판에 올려주세요.

폼에는 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.



+ -

관련 글 리스트
7088 [답변] PETIPRIN/ Edit에 특정키가 입력되지 않으려면.. k2453540 654 2000/03/13
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.