 |
|
|
Informatik |
|
Autor: be
21.09.2005 10:42 440
|
|
|
Absoluter Betrag Lösung
unit mAbsoluterBetrag;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
edZahl: TEdit;
edAbsoluterBetrag: TEdit;
btAbsoluterBetrag: TButton;
Label1: TLabel;
Label2: TLabel;
sbZahl: TScrollBar;
procedure btAbsoluterBetragClick(Sender: TObject);
procedure edZahlKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure sbZahlChange(Sender: TObject);
private
{ Private-Deklarationen }
procedure rechneBetrag;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btAbsoluterBetragClick(Sender: TObject);
begin
sbZahl.Position := StrToInt(edZahl.Text);
rechneBetrag;
end;
procedure TForm1.edZahlKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_RETURN then
begin
sbZahl.Position := StrToInt(edZahl.Text);
rechneBetrag;
end;
end;
procedure TForm1.sbZahlChange(Sender: TObject);
begin
edZahl.Text := IntToStr(sbZahl.Position);
rechneBetrag;
end;
procedure TForm1.rechneBetrag;
var zahl: Integer;
begin
zahl := StrToInt(edZahl.Text);
if zahl >= 0 then
edAbsoluterBetrag.Text:=IntToStr(zahl)
else
edAbsoluterBetrag.Text:=IntToStr(-zahl)
end;
end.