Autor Beitrag
hube
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

WIN XP
D7 Prof
BeitragVerfasst: Do 27.01.05 16:32 
Hallo

Ich möchte bei einem Edit.Text Feld die Zahl automatisch mit zwei Kommastellen haben. Wenn ich zum Beispiel 25 eingebe, soll 0,25 im Edit.Text stehen. Wenn ich 300 eingebe, soll 3,00 stehen.
Hat jemand eine Ahnung wie ich dies realisieren kann?
Es hat hier im Forum ein Beispiel (Kasse), aber das funkt nicht, dh es ändert die Caption vom Form ab.

Kann mir bitte jemand helfen?

Gruss hube
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: Do 27.01.05 16:53 
hallo hube!

sieh dir das TMaskEdit an. damit sollte sich dein problem ganz einfach lösen lassen

_________________
mfg, stefan


Zuletzt bearbeitet von grayfox am Do 27.01.05 17:36, insgesamt 1-mal bearbeitet
hube Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

WIN XP
D7 Prof
BeitragVerfasst: Do 27.01.05 17:10 
Hab's rausgefunden.

Das mit dem Maskedit passte mir nicht. Jetzt sieht's so aus:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var   s:String; 
i,d:Integer; 
begin

if Length(Edit1.Text)=0 then begin Txt:=''; Ausgabe_str:=''; end;
if (Key in ['0'..'9']) then
        begin 
        Txt:=Txt+Key;
        Ausgabe_str:=Txt;
        for d:=1 to 3-Length(Txt) do
        begin 
        Ausgabe_str:='0'+Ausgabe_str;
        end;
        s:='.';
        i:=Length(Ausgabe_str)-1;
        Insert (s, Ausgabe_str, i);
        Edit1.Text:=Ausgabe_str;
        Edit1.SelStart := Length(Edit1.Text);
        Key:=#0;

        end else if (Key in[#8]) then
                begin
                Txt:='';
                Edit1.Text:='';
                Ausgabe_str:='';
                end;
end;

procedure TForm1.Edit1Click(Sender: TObject);
begin
Edit1.SelStart := Length(Edit1.Text);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := Edit1.Text;
end;



Diese Lösung ist nicht von mir, ich habe sie nur soweit abgeändert, dass die Variable Txt (vorher Text) nicht mit der Beschriftung des Forms in die Quere kommt.

Trotzdem besten Dank

hube

Moderiert von user profile iconUGrohne: Delphi-Tags hinzugefügt und Code gekürzt.