#include #pragma hdrstop #include "MainForm.h" #include "GetValue.h" //--------------------------------------------------------------------- #pragma resource "*.dfm" #pragma warn -8080 TDlgGetValue *DlgGetValue; //--------------------------------------------------------------------- __fastcall TDlgGetValue::TDlgGetValue(TComponent* AOwner) : TForm(AOwner) { } //--------------------------------------------------------------------- void __fastcall TDlgGetValue::FormActivate(TObject *Sender) { GetValueBox->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TDlgGetValue::GetValueBarChange(TObject *Sender) { bInBar = true; if (bInBox == false) { GetValueBox->Text = IntToStr(GetValueBar->Position); } bInBar = false; } //--------------------------------------------------------------------------- void __fastcall TDlgGetValue::GetValueBoxChange(TObject *Sender) { int nTemp; AnsiString StrTemp; nTemp = 10; if ((GetValueBox->Text.Length() == 0) || (GetValueBox->Text == "-")) OKBtn->Enabled = false; else OKBtn->Enabled = true; if ((GetValueBox->Text == "-") && (GetValueBox->Text.Length() > 1)) return; StrTemp = GetValueBox->Text; if (GetValueBox->Text.Length() > 0) { if (GetValueBox->Text[1] == '-') { StrTemp.Delete(1,1); if (StrTemp.IsEmpty() != true) nTemp = - StrToInt(StrTemp); } else nTemp = StrToInt(StrTemp); } bInBox = true; if (bInBar == false) { if (GetValueBox->Text.Length() > 0) { if ((nTemp <= GetValueBar->Max) && (nTemp >= GetValueBar->Min)) GetValueBar->Position = nTemp; } } bInBox = false; } //--------------------------------------------------------------------------- void __fastcall TDlgGetValue::OKBtnClick(TObject *Sender) { if (GetValueBox->Text.Length() > 0) { if ((StrToInt(GetValueBox->Text) <= GetValueBar->Max) && (StrToInt(GetValueBox->Text) >= GetValueBar->Min)) { bGetValueGo = true; nChangeValue = GetValueBar->Position; ModalResult = mrOk; } } } //--------------------------------------------------------------------------- void __fastcall TDlgGetValue::CancelBtnClick(TObject *Sender) { ModalResult = mrCancel; } //--------------------------------------------------------------------------- void __fastcall TDlgGetValue::InitTheForm( AnsiString Title, AnsiString UnitType, int UnitMax, int UnitMin, int UnitInit, int LargeStep, int SmallStep, bool ResizeHorz) { Caption = Title; GetValueType->Caption = UnitType; GetValueBar->Max = UnitMax; GetValueBar->Min = UnitMin; GetValueBar->Position = UnitInit; GetValueBox->Text = IntToStr(UnitInit); GetValueBar->LargeChange = (Word)LargeStep; GetValueBar->SmallChange = (Word)SmallStep; bGetValueGo = false; Resize_Horz->Checked = true; Resize_Horz->Visible = ResizeHorz; bInBox = False; bInBar = False; Left = (Screen->Width - Width) / 2; Top = (Screen->Height - Height) / 2; } //--------------------------------------------------------------------------- bool __fastcall TDlgGetValue::UserResult(void) { return (bGetValueGo); } //--------------------------------------------------------------------------- bool __fastcall TDlgGetValue::GetResizeHorz(void) { if (Resize_Horz->Checked == true) return(true); else return(false); } //--------------------------------------------------------------------------- int __fastcall TDlgGetValue::GetAmount(void) { return(nChangeValue); } //--------------------------------------------------------------------------- void __fastcall TDlgGetValue::GetValueBoxKeyPress(TObject *Sender, char &Key) { if (GetValueBox->Text.Length() >= 1) { if (!((Key >= '0') && (Key <= '9')) && (Key != ' ') && (Key != '\b')) Key = NULL; } else { if (!((Key >= '0') && (Key <= '9')) && (Key != ' ') && (Key != '-') && (Key != '\b')) Key = NULL; } } //---------------------------------------------------------------------------