E sad........ Nasao se novi problem....... Ja sam odradila dodatne funkcije, kako sam mislila da treba, i sad on meni odradi funkciju, ali je ne pakuje u memoriju.... Evo program, pa ako neko moze da mi ispravi sta treba, ili da mi pomogne... Hvala..... :-(
Code:
unit calc;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Menus, StdCtrls, Mask, Buttons, ExtCtrls,
Clipbrd, About;
type
TCalcForm = class(TForm)
MemButton: TSpeedButton;
DecButton: TSpeedButton;
Button7: TSpeedButton;
Button8: TSpeedButton;
Button9: TSpeedButton;
Button4: TSpeedButton;
Button5: TSpeedButton;
Button6: TSpeedButton;
Button1: TSpeedButton;
Button2: TSpeedButton;
Button3: TSpeedButton;
Button0: TSpeedButton;
PlusMinusButton: TSpeedButton;
EqualButton: TSpeedButton;
DivButton: TSpeedButton;
TimesButton: TSpeedButton;
MinusButton: TSpeedButton;
PlusButton: TSpeedButton;
MemBevel: TBevel;
MemLabel: TLabel;
DecBevel: TBevel;
DecLabel: TLabel;
LineBevel: TBevel;
ClearButton: TSpeedButton;
ClearEntryButton: TSpeedButton;
BackButton: TSpeedButton;
BitBtn1: TBitBtn;
ButtonLog: TSpeedButton;
ButtonLn: TSpeedButton;
ButtonExp: TSpeedButton;
ButtonAbs: TSpeedButton;
ButtonSin: TSpeedButton;
ButtonCos: TSpeedButton;
ButtonPi: TSpeedButton;
ButtonSqrt: TSpeedButton;
procedure CalcExitMenuItemClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ButtonDigitClick(Sender: TObject);
procedure ClearEntryButtonClick(Sender: TObject);
procedure ClearButtonClick(Sender: TObject);
procedure BackButtonClick(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure OpButtonClick(Sender: TObject);
procedure EqualButtonClick(Sender: TObject);
procedure PlusMinusButtonClick(Sender: TObject);
procedure Copy1Click(Sender: TObject);
procedure Paste1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure ButtonPiClick(Sender: TObject);
procedure ButtonLogClick(Sender: TObject);
procedure ButtonLnClick(Sender: TObject);
procedure ButtonExpClick(Sender: TObject);
procedure ButtonAbsClick(Sender: TObject);
procedure ButtonSinClick(Sender: TObject);
procedure ButtonCosClick(Sender: TObject);
procedure ButtonSqrtClick(Sender: TObject);
private
{- Entry-radix switches. Only one can be true! }
DecEntry: Boolean;
{- Enable and disable buttons depending on Entry radix }
procedure EnableButtons;
{- Update Dec Labels from Accumulator }
procedure UpdateDigitLabels;
{- Update Accumulator value from current entry string }
procedure UpdateAccumulator;
{- Assign value to memory (intermediate) accumulator }
procedure SetMemAcc(V: Longint);
{- Display error message }
procedure ShowError(const Msg: String);
public
{ Public declarations }
end;
var
CalcForm: TCalcForm;
implementation
uses Math;
var M:real=0;
{$R *.DFM}
const
{ -2147483648 }
maxDecDigits = 11; { Maximum number of decimal digits }
opNo = 0; { Operators = button Tag properties }
opMultiply = -1;
opDivide = -2;
opAdd = -3;
opSubtract = -4;
asciiEsc = #27; { Ascii escape control code }
asciiEnter = #13; { Ascii enter control code }
var
Accumulator: Longint; { Current result }
MemAcc: Longint; { Memory result }
Operator: Integer; { opX constant }
DecString: String[maxDecDigits]; { Result in decimal }
{- Global procedures -- for Xtrastuff??? }
{ Convert string S in decimal to Longint value }
function StringToInt(const S: String): Longint;
begin
if Length(S) = 0 then
Result := 0
else try
Result := StrToInt(S);
except
on E: Exception do
begin
CalcForm.ShowError(E.Message);
Result := 0;
end;
end;
end;
{- Private methods }
{ Enable and disable buttons depending on entry radix }
procedure TCalcForm.EnableButtons;
begin
Button0.Enabled := True;
Button1.Enabled := True;
Button2.Enabled := True;
Button3.Enabled := True;
Button4.Enabled := True;
Button5.Enabled := True;
Button6.Enabled := true;
Button7.Enabled := true;
Button8.Enabled := true;
Button9.Enabled := true;
end;
{ Update global strings and Label captions from Accumulator }
procedure TCalcForm.UpdateDigitLabels;
begin
{- Convert accumulator value to strings }
DecString := IntToStr(Accumulator);
{- Assign strings to Label object Captions }
DecLabel.Caption := DecString;
end;
{- Update Accumulator value from current entry string }
procedure TCalcForm.UpdateAccumulator;
begin
try
if DecEntry then
Accumulator := StringToInt(DecString)
except
on E: EIntError do
ShowError(E.Message);
end;
end;
{- Assign V to MemAcc and update Memory display line }
procedure TCalcForm.SetMemAcc(V: Longint);
begin
MemAcc := V;
MemLabel.Caption := IntToStr(MemAcc);
end;
{- Display error message string }
procedure TCalcForm.ShowError(const Msg: String);
begin
MessageDlg(Msg, mtError, [mbOk], 0);
end;
{- End program on selecting Close button }
procedure TCalcForm.CalcExitMenuItemClick(Sender: TObject);
begin
Close;
end;
{- Initialize program on form's creation }
procedure TCalcForm.FormCreate(Sender: TObject);
begin
Accumulator := 0; { Zero accumulator } {-2147483647 - 1;}
MemAcc := 0; { Zero intermediate accumulator }
Operator := opNo; { No operation in effect }
DecEntry := True; { Assume Decimal radix initially }
EnableButtons; { Enable buttons depending on radix }
UpdateDigitLabels; { Update display result labels }
end;
{- Respond to click of a digit button 0 through F }
procedure TCalcForm.ButtonDigitClick(Sender: TObject);
begin
{- Ignore button clicks if accumulators are full }
if Length(DecString) = maxDecDigits then Exit;
{- Append button tag to end of strings }
with Sender as TSpeedButton do
begin
if DecEntry then
DecString := DecString + IntToStr(Tag);
UpdateAccumulator; { Convert entry string to Longint value }
UpdateDigitLabels; { Update display result labels }
end;
end;
{- Change radix on clicking D, H, or B button }
{- Clear current entry (Accumulator) only }
procedure TCalcForm.ClearEntryButtonClick(Sender: TObject);
begin
Accumulator := 0;
UpdateDigitLabels;
end;
{- Clear current entry and memory (Accumulator and MemAcc) }
procedure TCalcForm.ClearButtonClick(Sender: TObject);
begin
Accumulator := 0;
UpdateDigitLabels;
SetMemAcc(0);
end;
{ Delete last digit entered }
procedure TCalcForm.BackButtonClick(Sender: TObject);
begin
if DecEntry then
Delete(DecString, Length(DecString), 1);
UpdateAccumulator; { Convert entry string to Longint value }
UpdateDigitLabels; { Update display result labels }
end;
{- Translate keypresses into button clicks }
procedure TCalcForm.FormKeyPress(Sender: TObject; var Key: Char);
var
Button: TButton;
begin
case Key of
asciiEsc: ClearButtonClick(Sender);
asciiEnter: EqualButtonClick(Sender);
'*': TimesButton.Click;
'/': DivButton.Click;
'+': PlusButton.Click;
'-': MinusButton.Click;
else begin
Button := TButton(FindComponent('Button' + Key));
if Button <> nil then
if Button.Enabled then
Button.Click;
end;
end;
end;
{- Respond to click of an operator button (* / + - and or xor) }
{- Start math operation }
procedure TCalcForm.OpButtonClick(Sender: TObject);
begin
if Operator <> opNo then
EqualButtonClick(Sender);
SetMemAcc(Accumulator);
Operator := TButton(Sender).Tag;
Accumulator := 0;
UpdateDigitLabels;
end;
{- Respond to click of equal button. Complete math operation. }
procedure TCalcForm.EqualButtonClick(Sender: TObject);
begin
try
case Operator of
opMultiply : Accumulator := MemAcc * Accumulator;
opDivide : Accumulator := MemAcc div Accumulator;
opAdd : Accumulator := MemAcc + Accumulator;
opSubtract : Accumulator := MemAcc - Accumulator;
end;
except
on E: EIntError do
if E is EDivByZero then
ShowError('Divide by zero')
else if E is ERangeError then
ShowError('Out of range')
else if E is EIntOverflow then
ShowError('Overflow');
end;
UpdateDigitLabels;
Operator := opNo;
SetMemAcc(0);
end;
{- Respond to +/- button click }
procedure TCalcForm.PlusMinusButtonClick(Sender: TObject);
begin
Accumulator := -Accumulator;
UpdateDigitLabels;
end;
{- Copy current radix string to clipboard }
procedure TCalcForm.Copy1Click(Sender: TObject);
begin
if DecEntry then
Clipboard.AsText := DecString;
end;
{- Paste clipboard text to current radix string }
procedure TCalcForm.Paste1Click(Sender: TObject);
begin
if Clipboard.HasFormat(cf_Text) then
begin
if DecEntry then
DecString := Clipboard.AsText;
UpdateAccumulator;
UpdateDigitLabels;
end;
end;
procedure TCalcForm.About1Click(Sender: TObject);
begin
AboutForm.ShowModal;
end;
procedure TCalcForm.ButtonPiClick(Sender: TObject);
begin
DecLabel.Caption:=Floattostr(Pi);
end;
procedure TCalcForm.ButtonLogClick(Sender: TObject);
begin
declabel.Caption:=floattostr(log10(strtofloat(declabel.Caption)));
end;
procedure TCalcForm.ButtonLnClick(Sender: TObject);
begin
declabel.Caption:=floattostr(Ln(strtofloat(declabel.Caption)));
end;
procedure TCalcForm.ButtonExpClick(Sender: TObject);
begin
declabel.Caption:=floattostr(Exp(strtofloat(declabel.Caption)));
end;
procedure TCalcForm.ButtonAbsClick(Sender: TObject);
begin
declabel.Caption:=floattostr(Abs(strtofloat(declabel.Caption)));
end;
procedure TCalcForm.ButtonSinClick(Sender: TObject);
begin
declabel.Caption:=floattostr(Sin(strtofloat(declabel.Caption)));
end;
procedure TCalcForm.ButtonCosClick(Sender: TObject);
begin
declabel.Caption:=floattostr(Cos(strtofloat(declabel.Caption)));
end;
procedure TCalcForm.ButtonSqrtClick(Sender: TObject);
begin
declabel.Caption:=floattostr(Sqrt(strtofloat(declabel.Caption)));
end;
end.
[Ovu poruku je menjao savkic dana 16.05.2010. u 23:21 GMT+1]