Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox) (https://www.delphipraxis.net/172994-nur-das-groesste-ergebnis-wird-angegeben-rechner-mit-checkbox-und-radiobox.html)

ItsMe1 1. Feb 2013 17:14

Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
 
Hey Leute,
ich hab noch eine Frage...
Ich möchte gerne das mein "Taschenrechner" die Editfelder mit dem dazugehörigen Hacken in der Checkbox addiert.
Mein Problem ist es das immer nur zwei zahlen zusammengerechnet werden oder halt nicht nur die wo ein hacken in der Checkbox ist :( ....
Hier der Code:
Code:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
  if radiobutton1.Checked = true and Checkbox1.Checked = true and Checkbox2.Checked =true then
    begin
      label7.Caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit2.Text));
    end;

  if radiobutton1.Checked = true and checkbox1.Checked =true and checkbox3.Checked =true then
    begin
      label7.caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit3.Text));
    end;

  if radiobutton1.Checked = true and Checkbox1.Checked = true and Checkbox4.Checked =true then
    begin
      label7.Caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit4.Text));
    end;

  if radiobutton1.Checked = true and checkbox2.Checked =true and checkbox3.Checked =true then
    begin
      label7.caption:= floattostr(strtofloat(edit2.Text)+strtofloat(edit3.Text));
    end;

  if radiobutton1.Checked = true and Checkbox2.Checked = true and Checkbox4.Checked =true then
    begin
      label7.Caption:= floattostr(strtofloat(edit2.Text)+strtofloat(edit4.Text));
    end;

  if radiobutton1.Checked = true and checkbox3.Checked =true and checkbox4.Checked =true then
    begin
      label7.caption:= floattostr(strtofloat(edit3.Text)+strtofloat(edit4.Text));
    end;

  if radiobutton1.Checked = true and Checkbox1.Checked = true and Checkbox2.Checked =true and Checkbox3.Checked =true then
    begin
      label7.Caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit2.Text)+strtofloat(edit3.Text));
    end;

  if radiobutton1.Checked = true and checkbox1.Checked =true and checkbox3.Checked =true and Checkbox4.Checked =true then
    begin
      label7.caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit3.Text)+strtofloat(edit4.Text));
    end;

  if radiobutton1.Checked = true and Checkbox4.Checked = true and Checkbox2.Checked =true and Checkbox3.Checked =true then
    begin
      label7.Caption:= floattostr(strtofloat(edit4.Text)+strtofloat(edit2.Text)+strtofloat(edit3.Text));
    end;

  if radiobutton1.Checked = true and checkbox1.Checked =true and checkbox2.Checked =true and Checkbox3.Checked =true and Checkbox4.Checked =true then
    begin
      label7.caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit2.Text)+strtofloat(edit3.Text)+strtofloat(edit4.Text));
    end;



end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  close;
end;

end.
Vielen Dank schon mal für die Hilfe :-D
Grüße ItsMe1

EWeiss 1. Feb 2013 17:21

AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
 
Delphi-Quellcode:
if radiobutton1.Checked = true and Checkbox1.Checked = true and Checkbox2.Checked =true then


Ohh das mag DeddyH gar nicht ;)

gruss

ItsMe1 1. Feb 2013 17:27

AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
 
Ahhh.... bin neu hier (hab erst angefangen mit Programmieren) kannst du mir bitte sagen was da falsch ist und wie ich es verbessern kann
Danke

Olli73 1. Feb 2013 17:36

AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
 
Code:
procedure TForm1.Button2Click(Sender: TObject);
begin
  if radiobutton1.Checked then begin
    label7.Caption := '0';
    if checkbox1.Checked then
      label7.caption := floattostr(strtofloat(label7.caption) + strtofloat(edit1.Text));
    if checkbox2.Checked then
      label7.caption := floattostr(strtofloat(label7.caption) + strtofloat(edit2.Text));
    if checkbox3.Checked then
      label7.caption := floattostr(strtofloat(label7.caption) + strtofloat(edit3.Text));
    if checkbox4.Checked then
      label7.caption := floattostr(strtofloat(label7.caption) + strtofloat(edit4.Text));
  end;
end;

DeddyH 1. Feb 2013 17:41

AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
 
Zitat:

Zitat von EWeiss (Beitrag 1201694)
Delphi-Quellcode:
if radiobutton1.Checked = true and Checkbox1.Checked = true and Checkbox2.Checked =true then


Ohh das mag DeddyH gar nicht ;)

gruss

Ohh, Du hast ja so Recht ;)

[edit] Begründung [/edit]

ItsMe1 1. Feb 2013 17:42

AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
 
Danke für die schnelle Antwort
Gruss

DeddyH 1. Feb 2013 18:03

AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
 
Nachtrag: wenn Du mehrere Vergleiche als Bedingung verknüpfen willst, musst Du jeden einzelnen Vergleich in Klammern einschließen.
Delphi-Quellcode:
if (a = 10) and (b < 5) and (c = 42) then

Sir Rufo 1. Feb 2013 19:46

AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
 
[OT]
Wie kommt man eigentlich darauf bei einer CheckBox vom einem Hacken zu sprechen?
Das scheint immer beliebter zu werden, aber ...

Wird hier auf etwas herumgehackt?
Ist hier ein Hacker am Werk?
Wurde etwas mit einem Hackbrett erfasst?

Haken oder Häkchen könnte ich verstehen, aber so... :gruebel:
[/OT]

evilboy 2. Feb 2013 00:39

AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
 
Zitat:

Zitat von Sir Rufo (Beitrag 1201704)
[OT]
Wie kommt man eigentlich darauf bei einer CheckBox vom einem Hacken zu sprechen?
Das scheint immer beliebter zu werden, aber ...

Wird hier auf etwas herumgehackt?
Ist hier ein Hacker am Werk?
Wurde etwas mit einem Hackbrett erfasst?

Haken oder Häkchen könnte ich verstehen, aber so... :gruebel:
[/OT]

(OT) Neulich durfte ich Seminararbeiten korrigieren und da war auch schon mal von "Hackenkreuz" die Rede. Aber so wird es nicht mal ausgesprochen… (Wobei, über manche anderen Sprachtrends kann ich mich auch nur aufregen :roll: )

Bummi 2. Feb 2013 07:50

AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
 
Delphi-Quellcode:
var
 i:Integer;
 sum:Double;
begin
   sum := 0;
   if RadioButton1.checked then
      begin
         for I := 1 to 4 do
           if TCheckBox(FindComponent('Checkbox' + IntToStr(i))).Checked then
             Sum := Sum +  StrToFloat(TEdit(FindComponent('Edit' + IntToStr(i))).Text);
         Label7.Caption := FloatToStr(sum);
      end;
end;
wobei der Zugriff über eigene Listen oder Array mit den Komponenten flotter wäre.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:57 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz