![]() |
|
inputbox'a sadece harf / sayı gimek ? - Baskı Önizleme +- Delphi Can (https://www.delphican.com) +-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3) +--- Forum: Genel Programlama (https://www.delphican.com/forumdisplay.php?fid=6) +--- Konu Başlığı: inputbox'a sadece harf / sayı gimek ? (/showthread.php?tid=6146) |
inputbox'a sadece harf / sayı gimek ? - cooxed - 30-06-2021 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. Cvp: inputbox'a sadece harf / sayı gimek ? - cinarbil - 30-06-2021 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;
inputbox'a sadece harf / sayı gimek ? - mcuyan - 30-06-2021 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; |