Autor Beitrag
Thunder
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 145

WinXP
D6 Pers
BeitragVerfasst: So 25.01.04 13:59 
Moin,

Mein Problem:
Ich habe ein TMaskEdit.
Meine EditMask:
ausblenden Quelltext
1:
     000,00 €;1;_					

Ich möchte mit der Eingabe in der TMaskEdit rechnen. Dazu brauche ich daraus ein Integerwert. Dazu muss ich aus TMaskEdit.Text, das ein String ist, die dezimalen Zahlen rausfiltern um diese mit StrToInt in ein Integerwert umzuwandeln

Meine Lösung:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var s: String;
    i: Integer;

  s := MaskEdit1.Text;
  Trim(s);
  s := StringReplace(s, ',', '',[rfReplaceAll, rfIgnoreCase]);
  s := StringReplace(s, ' ', '',[rfReplaceAll, rfIgnoreCase]);
  s := StringReplace(s, '€', '',[rfReplaceAll, rfIgnoreCase]);
  i := StrToInt(s);


Wenn ihr das auf euer TMaskEdit anwenden wollt, müsst ihr den zweiten Parameter im StringReplace (hier >','< >' '< >'€'<) natürlich an eure verwendeten Zeichen ändern.

Verbesserungsmöglichkeiten:
Wer hat eine Lösung, den zweiten Parameter in StringReplace, das Zeichen was ausgetauscht werden soll gegen den dritten Parameter, mit mehreren zu suchenden Zeichen auszustatten, um nur einmal StringReplace aufrufen zu können?




Ich hoffe ich konnte euch helfen. Ich habe mir zumindest geholfen ;)


Zuletzt bearbeitet von Thunder am So 25.01.04 23:10, insgesamt 2-mal bearbeitet
FriFra
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: So 25.01.04 15:05 
Ich verstehe Deine Frage/Problem zwar nicht ganz... aber hast Du es schon so versucht

ausblenden Delphi-Quelltext
1:
StrToIntDef(Trim(MaskEdit1.text), 0)					

_________________
Michael
(principal certified lotus professional - developer)
Thunder Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 145

WinXP
D6 Pers
BeitragVerfasst: So 25.01.04 17:41 
ich denke das is des richtige. ich probiers ;)

hmm das ding gibt immer 0 egal was ich mach... :(

das isses irgendwie nich...

ausblenden Quelltext
1:
2:
3:
4:
5:
hier noch ma die Daten:
MaskEdit1:

EditMask =      000,00 €;1;_
Text =         ,   €


So und so teste ich das:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.MaskEdit1DblClick(Sender: TObject);
var s: String;
begin
  i := StrToIntDef(Trim(MaskEdit1.Text), 0);
  s := IntToStr(i);
  ShowMessage(s);
end;


So ich gebe in die MaskEdit
ausblenden Quelltext
1:
55555					

Also steht da dann
ausblenden Quelltext
1:
     555,55 €					


So und ich will jetz daraus den Integerwert 55555 haben um damit weiterzuarbeiten... jetz klar??
So auf den Integerwert 55555 rechne ich jetz noch 11111 drauf und habe 66666. das will ich in eine MaskEdit2 übergeben. in dieser soll dann statt
66666 natürlich
ausblenden Quelltext
1:
     666,66 €					


stehen. Jetz alle verstannden???
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: So 25.01.04 19:05 
du musst zuerst alle zeichen, die keine zahlen sind aus dem string rauswerfen, damit du das in einen integer umwandeln kannst !

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Thunder Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 145

WinXP
D6 Pers
BeitragVerfasst: So 25.01.04 21:04 
ach nee...

hab schon n befehl gefunden der das scheint zu tun... s := Format(...);
Thunder Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 145

WinXP
D6 Pers
BeitragVerfasst: So 25.01.04 23:01 
gelöst! Lösung oben!!
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mo 26.01.04 17:10 
nicht die eleganteste lösung aber funktionell !

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Thunder Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 145

WinXP
D6 Pers
BeitragVerfasst: Mo 26.01.04 17:49 
schlägste schnell was besseres vor :lol:
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 27.01.04 16:11 
ich hab auf die schnelle nix besseres. ich hab aber auch nix dagagegen gesagt. es funktioniert und damit basta !

_________________
In the beginning was the word.
And the word was content-type: text/plain.