Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Polje Edit - Samo brojevi

[es] :: Pascal / Delphi / Kylix :: Polje Edit - Samo brojevi

[ Pregleda: 3515 | Odgovora: 10 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Dwiz

Član broj: 27171
Poruke: 124
*.cmu.carnet.hr



Profil

icon Polje Edit - Samo brojevi19.09.2004. u 19:32 - pre 238 meseci
Kako u delhiju napraviti da se u polje edit ne može unijeti tekst, samo brojevi. Da se ništa ne ispisuje kada tipkam slova, nego samo kada tipkam brojeve.
 
Odgovor na temu

bancika
Branislav Stojkovic

Član broj: 24844
Poruke: 631
212.62.58.*

Sajt: www.diy-fever.com


+1 Profil

icon Re: Polje Edit - Samo brojevi19.09.2004. u 19:41 - pre 238 meseci
pa mozes malo na silu, na OnChange stavi
Code:

i := 1;
while i <= Length(Edit1.Text) do
 if not (Edit1.Text[i] in ['0'..'9']) then
  Delete(Edit1.Text, i, 1)
 else Inc(i);

moguce da Edit1.Text ne moze da se stavi kao parametar u Delete, al mozes da koristis pomocni string.

Bolje resenje je da presretnes poruku i da promenis, samo sto to nisam najsigurniji. Stavi ApplicationEvents komponentu i pod OnMessage stavi
Code:

if (Msg.message = WM_KEYDOWN) and (Edit1.HasFocus) and not (Msg.wParam in [Ord('0')..Ord('9')]) then
 Msg.wParam := 0;


nemoj da me drzis za rec, ovo ti je samo ideja, ovako iz glave :)\

pozdrav
Ride the rainbow, crack the sky

DIY gitare, pojacala i efekti www.diy-fever.com
 
Odgovor na temu

Almedin

Član broj: 5895
Poruke: 425
*.as54.tz.bih.net.ba.



+27 Profil

icon Re: Polje Edit - Samo brojevi19.09.2004. u 19:43 - pre 238 meseci
Obrađuj događaj OnKeyPress. Ako nije pritisnut broj uradi Key := Chr(0).
 
Odgovor na temu

kefalo
Banjaluka, RS, BiH

Član broj: 18959
Poruke: 263
*.dip.urc.bl.ac.yu

ICQ: 178873696
Sajt: home.blic.net/mozlas


+6 Profil

icon Re: Polje Edit - Samo brojevi20.09.2004. u 16:33 - pre 238 meseci
a zasto ne bi koristio maskedit?
 
Odgovor na temu

Dwiz

Član broj: 27171
Poruke: 124
*.cmu.carnet.hr



Profil

icon Re: Polje Edit - Samo brojevi20.09.2004. u 17:23 - pre 238 meseci
Ja bih u to polje trebao nekada unesiti npr. 3,00 a nekada 30,00, kako to napraviti s maskeditom?
 
Odgovor na temu

franjo_tahi
Franjo Tahi
Zagreb

Član broj: 34712
Poruke: 399
*.adsl.net.htnet.hr



+1 Profil

icon Re: Polje Edit - Samo brojevi21.09.2004. u 08:18 - pre 238 meseci
Radio sam kontrolicu koja bi trebala biti to sto ti treba. Nije skroz zgotovljena, ali vidis bit. Sad sam na poslu, doma imam noviju verziju koja bolje radi. ako ti treba, posaljem ti poslije 20h.

unit NumEdit;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, mask;

type
TNumEdit = class(TMaskEdit)
private
{ Private declarations }
FDecimals : Integer; // Number of decimals for rounding
FKeyPressed : Boolean; // Keypressed
FAlignment : TAlignment;
Function RoundedText(aText : String) : String; // Perform the rounding
procedure KeyPress(var Key: Char); override;
procedure DoExit; override;
procedure DoEnter; override;
procedure Change; override;
procedure SetDecimal(Br:integer);
Function GetNumber:Extended;
procedure SetNumber(Br:Extended);
property EditMask;
public
{ Public declarations }
Constructor Create (AOwner : TComponent); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure SetAlignment(Value: TAlignment);
property KeyPressed : boolean read FKeyPressed write FKeyPressed default False;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
published
{ Published declarations }
//new properties
property Decimals : Integer read FDecimals write SetDecimal;
property Number:Extended read GetNumber write SetNumber;
//publishing properties we want
property Anchors;
property AutoSelect;
property AutoSize;
property BiDiMode;
property BorderStyle;
property CharCase;
property Color;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property ImeMode;
property ImeName;
property MaxLength;
property OEMConvert;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;

procedure Register;

implementation

procedure TNumEdit.SetNumber(Br:Extended);
begin
text:=RoundedText(floattostr(br));
end;

function TNumEdit.GetNumber:Extended;
begin
try
result := strtofloat(text);
except
result := 0;
end;
end;

procedure TNumEdit.SetDecimal(Br:integer);
var s:string;
//i:integer;
begin
FDecimals := Br;
s:=RoundedText(Text);
//i:=pos(DecimalSeparator, s);
self.EditMask := '!'+StringOfChar('9', MaxLength - Br -1)+DecimalSeparator+StringOfChar('9', Br);
self.Text := s;
end;

Constructor TNumEdit.Create (AOwner : TComponent);
begin
Inherited Create(AOwner);
SetAlignment(taRightJustify);
MaxLength := 10;
EditMask := '!9999999'+DecimalSeparator+'99;1;_';
FDecimals := 2;
self.Text := '0.00';
end;

procedure TNumEdit.CreateParams(var Params: TCreateParams);
const
Alignments: array[Boolean, TAlignment] of DWORD =
((ES_LEFT, ES_RIGHT, ES_CENTER),(ES_RIGHT, ES_LEFT, ES_CENTER));
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style or ES_MULTILINE or
Alignments[UseRightToLeftAlignment, FAlignment];
end;
end;

procedure TNumEdit.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
RecreateWnd;
end;
end;

Function TNumEdit.RoundedText(aText : String) : String; //Perform rounding the text
var x:integer;
S1,S2:STRING;
begin
S1:='';
S2:='';
X:=1;
WHILE (X <= LENGTH(aTEXT)) AND (ATEXT[X] <> DecimalSeparator) do begin
if aText[x] in ['0'..'9'] then s1:=s1+aText[x];
x:=x+1;
end;
if s1 = '' then s1:='0';
while x <= length(aText) do begin
if aText[x] in ['0'..'9'] then s2:=s2+aText[x];
x:=x+1;
end;
if length(s2) < FDecimals then s2:=s2+StringOfChar('0', FDecimals-length(s2));
//FmtStr(Result,'%0.'+ IntToStr(RoundingDecimals) +'f',[StrToFLoat(Text)]);
result := s1+DecimalSeparator+s2;
KeyPressed := false;
end;

procedure TNumEdit.Change;
begin
//if not KeyPressed then
//begin
// if (Text <> '') then
// Text := RoundedText(Text);
//end
end;

procedure TNumEdit.DoEnter; // Perform rounding when entering
var i:integer;
begin
if (Text <> '') then begin
Text := RoundedText(Text);
i:=pos(DecimalSeparator, Text)-1;
if i < 1 then i:=length(text);
SelStart := 0;
SelLength := i;
end;
end;

procedure TNumEdit.DoExit; // Perform rounding when exiting
begin
if (Text <> '') then
Text := RoundedText(Text);
end;

procedure TNumEdit.KeyPress(var Key: Char);
begin
if key in [',', '.'] then key:=DecimalSeparator;
KeyPressed := true;
if key = DecimalSeparator then text:=RoundedText(Text);
Inherited KeyPress(Key); // For user events
//Check for Numeric and backspaces
{if not (Key in [#8, '0'..'9', '-', DecimalSeparator]) then
begin
KeyPressed := False;
key:=#0;
beep;
end else //Check for existing ofdecimalsepatator and '-'
if ((Key = DecimalSeparator) or (key = '-')) and (Pos(Key, Text) > 0) then
begin
If Key = DecimalSeparator then
begin
SelStart := Pos(Key, Text);
SelLength := Length(Text);
end;
key:=#0;
end else // If '-' then first check position at front
if (Key = '-') and (Selstart <> 0) then
begin
key:=#0;
beep;
end;}
end;

procedure Register;
begin
RegisterComponents('Moje', [TNumEdit]);
end;


end.
 
Odgovor na temu

Anarki

Član broj: 31007
Poruke: 116
*.vdial.verat.net

Jabber: rile@jabber.org


Profil

icon Re: Polje Edit - Samo brojevi22.09.2004. u 21:04 - pre 238 meseci
obradi OnChange event i izbrishi svaki uneti znak koji nije cifra i eventualno zarez, ako radish sa realnim brojevima

POz
I throw myself into the sea. Release the wave,
Let it wash over me, To face the fear,
I once believed The tears for the dragon
For you and for me
 
Odgovor na temu

Dwiz

Član broj: 27171
Poruke: 124
*.cmu.carnet.hr



Profil

icon Re: Polje Edit - Samo brojevi03.10.2004. u 18:42 - pre 237 meseci
Skužio sam uz pomoć Delphi helpa. Ovo je kod:
Code:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
 case key of
 '0': ;
 '1': ;
 '2': ;
 '3': ;
 '4': ;
 '5': ;
 '6': ;
 '7': ;
 '8': ;
 '9': ;
 ',': ;
 '.': ;
 else abort;
 end;

Jednostavno, zar ne!!!!
 
Odgovor na temu

Milos D
Beograd

Član broj: 5621
Poruke: 280
*.ptt.yu



+1 Profil

icon Re: Polje Edit - Samo brojevi04.10.2004. u 13:05 - pre 237 meseci
Ili, jednostavnije:

if not (Key in ['0'..'9', '.', ','])
then Key := #0;

Samo, to nece spreciti nadahnutog korisnika da ukuca npr. "21..,,,.,.,.,.1.21..21.21.2.1" ;)
 
Odgovor na temu

Nemanja Avramović
Engineering Manager
MENU Technologies
Beograd, Srbija

Član broj: 32202
Poruke: 4391
*.verat.net

Sajt: https://avramovic.info


+46 Profil

icon Re: Polje Edit - Samo brojevi04.10.2004. u 13:40 - pre 237 meseci
A sta od ovoga reaguje na copy|paste? Jel ste razmisljali o tome. Mrzi me da probam, samo cisto informativno pitam...
Laravel Srbija.

[NE PRUŽAM PODRŠKU ZA PHP PREKO PRIVATNIH PORUKA!]
 
Odgovor na temu

Dwiz

Član broj: 27171
Poruke: 124
*.cmu.carnet.hr



Profil

icon Re: Polje Edit - Samo brojevi04.10.2004. u 20:06 - pre 237 meseci
Ovo je samo osnovna ideja koju treba još doraditi!
 
Odgovor na temu

[es] :: Pascal / Delphi / Kylix :: Polje Edit - Samo brojevi

[ Pregleda: 3515 | Odgovora: 10 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.