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.
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.
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;