Konuyu Oyla:
  • Derecelendirme: 0/5 - 0 oy
  • 1
  • 2
  • 3
  • 4
  • 5
inputbox'a sadece harf / sayı gimek ?
#1
elimde şöyle ilerleyen bir kod satırı var

procedure TForm1.Button1Click(Sender: TObject);
begin
ad:=InputBox('Ad','Personelin Adını Giriniz:','');
Memo1.Lines.Add(ad);

örneğin ben adların bulunduğu memoya sadece yazı girilmesini , bir sonraki ( maaş bilgilerini içeren ) memoya da sadece sayı girilebilmesini istiyorum. bunu nasıl yapabilirim.
Cevapla
#2
Forma edit koyarsan onun yoksa formun onkeypress olayına
// if not (Key in [#8, '0'..'9', DecimalSeparator]) then

bu satır ile ister sayı ister karakter isterseniz özel karakterleri sınırlayabilirsiniz.



procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); 
begin 
 if not (Key in [#8, '0'..'9', DecimalSeparator]) then 
 begin
    ShowMessage('Geçersiz karakter: ' + Key); 
    Key := #0; 
 end 
 else 
 if (Key = DecimalSeparator) and (Pos(Key, Edit1.Text) > 0) then 
 begin 
   ShowMessage('Geçersiz işlem ' + Key); 
   Key := #0; 
 end; 
end;
"…De ki: "Hiç bilenlerle bilmeyenler bir olur mu? Şüphesiz, temiz akıl sahipleri öğüt alıp-düşünürler" (Zümer Suresi, 9)
Cevapla
#3
Ben özel Passinput kullanıyorum. Kodları aşağıda onkeyevent'ına @cinarbil  arkadaşımızın kodlarını eklerseniz işlem tamamdır.

function PassInput(const ACaption, APrompt: string; var Value: string): Boolean;
var
 Form: TForm;
 Prompt: TLabel;
 Edit: TEdit;
 DialogUnits: TPoint;
 ButtonTop, ButtonWidth, ButtonHeight: Integer;
begin
 Result := False;
 Form := TForm.Create(Application);
 with Form do
   try
     Canvas.Font := Font;
     DialogUnits := KarakterSize(Canvas);
     BorderStyle := bsDialog;
     Caption := ACaption;
     ClientWidth := MulDiv(180, DialogUnits.X, 4);
     Position := poScreenCenter;
     Prompt := TLabel.Create(Form);
     with Prompt do
     begin
       Parent := Form;
       Caption := APrompt;
       Left := MulDiv(8, DialogUnits.X, 4);
       Top := MulDiv(8, DialogUnits.Y, 8);
       Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);
       WordWrap := True;
     end;
     Edit := TEdit.Create(Form);
     with Edit do
     begin
       Parent := Form;
       Left := Prompt.Left;
       Top := Prompt.Top + Prompt.Height + 5;
       Width := MulDiv(164, DialogUnits.X, 4);
       MaxLength := 255;
       Text := Value;
       PasswordChar := '*';//Şifre yazmak için.. Şifreli olmasın istiyorsanız bu satırı kaldırın.
       SelectAll;
     end;
     ButtonTop := Edit.Top + Edit.Height + 15;
     ButtonWidth := MulDiv(50, DialogUnits.X, 4);
     ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
     with TButton.Create(Form) do
     begin
       Parent := Form;
       Caption := 'Tamam';
       ModalResult := mrOk;
       Default := True;
       SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth, ButtonHeight);
     end;
     with TButton.Create(Form) do
     begin
       Parent := Form;
       Caption := 'İptal';
       ModalResult := mrCancel;
       Cancel := True;
       SetBounds(MulDiv(92, DialogUnits.X, 4), Edit.Top + Edit.Height + 15, ButtonWidth, ButtonHeight);
       Form.ClientHeight := Top + Height + 13;
     end;
     if ShowModal = mrOk then
     begin
       Value := Edit.Text;
       Result := True;
     end;
   finally
     Form.Free;
   end;
end;
// Bilgi paylaştıkça çoğalır.. 

Cevapla


Konu ile Alakalı Benzer Konular
Konular Yazar Yorumlar Okunma Son Yorum
  Modelleme sayı kombinasyonu mersoy 13 3.596 25-08-2024, Saat: 09:02
Son Yorum: damert6
  harf olan kayıtları görmezden gelme ercanskose 9 2.984 30-01-2024, Saat: 11:26
Son Yorum: elixir84
  EnumWindows apisi sadece çalışan uygulamalar kofmaster 1 2.527 26-08-2023, Saat: 10:40
Son Yorum: veteran
  InputBox a sadece rakam girme. noname101 3 1.833 06-06-2023, Saat: 10:21
Son Yorum: COMMANDX
  Sadece Son Kayıtları Listeleme gonulali 4 1.984 09-05-2023, Saat: 17:01
Son Yorum: gonulali



Konuyu Okuyanlar: 1 Ziyaretçi