0,0 → 1,188 |
// akPi v2.2 |
// Copyright (c) 1997-99 Anatoli Klassen |
|
unit ShowUnit; |
|
interface |
|
uses |
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, |
ComCtrls, StdCtrls, LongIntegerUnit, ExtCtrls, Menus; |
|
type |
TShowForm = class(TForm) |
NumberLabel : TLabel; |
NumberEdit : TEdit; |
StatusBar : TStatusBar; |
StartButton : TButton; |
ResultBox : TGroupBox; |
CancelButton : TButton; |
AboutButton : TButton; |
ExitButton : TButton; |
ResultPopupMenu : TPopupMenu; |
CopyItem : TMenuItem; |
CopyAllItem : TMenuItem; |
SaveItem : TMenuItem; |
BreakLine : TMenuItem; |
SaveDialog : TSaveDialog; |
ResultText : TRichEdit; |
HelpButton: TButton; |
procedure StartButtonClick (Sender : TObject); |
procedure CancelButtonClick(Sender : TObject); |
procedure AboutButtonClick (Sender : TObject); |
procedure ExitButtonClick (Sender : TObject); |
procedure CopyItemClick (Sender : TObject); |
procedure CopyAllItemClick (Sender : TObject); |
procedure SaveItemClick (Sender : TObject); |
procedure FormCreate(Sender: TObject); |
procedure HelpButtonClick(Sender: TObject); |
private |
CalcThread : TThread; |
NDigit : longint; |
StartTime : TDateTime; |
Canceled : boolean; |
Pi : PChar; |
FCalcTime : string; |
procedure ThreadDone(Sender : TObject); |
function CalcTime : string; |
procedure ChangeMenuState(State : boolean); |
public |
end; |
|
var |
ShowForm : TShowForm; |
|
implementation |
|
uses CalcUnit, AboutUnit, ClipBrd; |
|
{$R *.DFM} |
|
procedure TShowForm.ThreadDone(Sender : TObject); |
begin |
StartButton.Visible := True; |
CancelButton.Visible := False; |
NumberEdit.Enabled := True; |
NumberEdit.SetFocus; |
|
if Canceled then StatusBar.SimpleText := 'Calculations is aborted' |
else begin |
StatusBar.SimpleText := 'Time of calculations: ' + CalcTime; |
ResultText.Text := Pi; |
FreeMem(Pi, Round(NDigit * 1.5)); |
ChangeMenuState(True); |
end; |
end; |
|
procedure TShowForm.StartButtonClick(Sender : TObject); |
begin |
NDigit := StrToIntDef(NumberEdit.Text, 100); |
if NDigit < 100 then NDigit := 100; |
if NDigit > MaxLongDigit * 4 - 40 then NDigit := MaxLongDigit * 4 - 40; |
NumberEdit.Text := IntToStr(NDigit); |
|
Canceled := False; |
StartTime := Now; |
StartButton.Visible := False; |
CancelButton.Visible := True; |
NumberEdit.Enabled := False; |
ChangeMenuState(False); |
|
ResultText.Lines.Clear; |
|
GetMem(Pi, Round(NDigit * 1.5)); |
CalcThread := TCalc.Create(StatusBar, NDigit, Pi); |
CalcThread.OnTerminate := ThreadDone; |
end; |
|
procedure TShowForm.CancelButtonClick(Sender : TObject); |
begin |
Canceled := True; |
CalcThread.Terminate; |
end; |
|
procedure TShowForm.AboutButtonClick(Sender : TObject); |
begin |
AboutBox.ShowModal; |
end; |
|
function TShowForm.CalcTime; |
var |
StopTime : TDateTime; |
S : string; |
|
begin |
StopTime := Now - StartTime; |
Result := TimeToStr(StopTime); |
if Int(StopTime) > 0 then begin |
S := Copy(Result, 1, Pos(':', Result) - 1); |
Delete(Result, 1, Pos(':', Result) - 1); |
Result := IntToStr(Trunc(StopTime) * 24 + StrToInt(S)) + Result; |
end; |
FCalcTime := Result; |
end; |
|
procedure TShowForm.ExitButtonClick(Sender : TObject); |
begin |
Close; |
end; |
|
procedure TShowForm.CopyItemClick(Sender : TObject); |
begin |
ResultText.CopyToClipboard; |
end; |
|
procedure TShowForm.CopyAllItemClick(Sender : TObject); |
begin |
Clipboard.AsText := ResultText.Lines.Text; |
end; |
|
procedure TShowForm.SaveItemClick(Sender : TObject); |
var |
i : longint; |
S : TStringList; |
st : string; |
|
begin |
if SaveDialog.Execute then begin |
S := TStringList.Create; |
|
for i := 0 to ResultText.Lines.Count - 1 do begin |
st := ResultText.Lines[i]; |
if st[1] = ' ' then Delete(st, 1, 1); |
S.Add(st); |
end; |
S.Add(FCalcTime); |
|
S.SaveToFile(SaveDialog.FileName); |
S.Free; |
end; |
end; |
|
procedure TShowForm.ChangeMenuState(State : boolean); |
begin |
CopyItem.Enabled := State; |
CopyAllItem.Enabled := State; |
SaveItem.Enabled := State; |
end; |
|
function AddBackslash(const Path : string) : string; |
begin |
if Path = '' then Result := Path |
else |
if Path[Length(Path)] = '\' then Result := Path |
else Result := Path + '\'; |
end; |
|
procedure TShowForm.FormCreate(Sender: TObject); |
begin |
Application.HelpFile := |
AddBackslash(ExtractFileDir(Application.ExeName)) + 'akpi.hlp'; |
end; |
|
procedure TShowForm.HelpButtonClick(Sender: TObject); |
begin |
Application.HelpContext(1); |
end; |
|
end. |