//--------------------------------------------------------------------------- void __fastcall TFNoSenseRestProp::BtOkClick(TObject *Sender) { TEdit *Ex; try { Ex = EA; A = StrToFloat(EA->Text); Ex = EB; B = StrToFloat(EB->Text); Ex = EA; K = StrToFloat(EK->Text); Ex = EdX; dX = StrToFloat(EdX->Text); Ex = EdY; dY = StrToFloat(EdY->Text); } catch(...) { Application->MessageBoxA("Неверный формат числа", "Floating Poitn Error", MB_OK | MB_ICONERROR); Ex->SetFocus(); return; } ResultOk = true; Close(); }
//--------------------------------------------------------------------------- bool TMillersForm::CalcIndex(void) { bool bRet = true; AnsiString S; TEdit *pIndexEdit; try { if(DirectIndexHEdit->Text != "" && DirectIndexHEdit->Text != "" && DirectIndexHEdit->Text != "") { pIndexEdit = DirectIndexHEdit; MI.h = pIndexEdit->Text.ToDouble(); pIndexEdit = DirectIndexKEdit; MI.k = pIndexEdit->Text.ToDouble(); pIndexEdit = DirectIndexLEdit; MI.l = pIndexEdit->Text.ToDouble(); TMillersIndexes PerpMI; PerpMI = MI.Perpend(); PerpIndexHEdit->Text = AnsiString().sprintf("%.2f",PerpMI.h); PerpIndexKEdit->Text = AnsiString().sprintf("%.2f",PerpMI.k); PerpIndexLEdit->Text = AnsiString().sprintf("%.2f",PerpMI.l); if(AngleIndexHEdit->Text != "" && AngleIndexKEdit->Text != "" && AngleIndexLEdit->Text != "") { TMillersIndexes AngelMI; pIndexEdit = AngleIndexHEdit; AngelMI.h = pIndexEdit->Text.ToDouble(); pIndexEdit = AngleIndexKEdit; AngelMI.k = pIndexEdit->Text.ToDouble(); pIndexEdit = AngleIndexLEdit; AngelMI.l = pIndexEdit->Text.ToDouble(); double dAngle = MI.Angle(AngelMI); AngleValueLabel->Caption = AnsiString().sprintf("%.2f",dAngle);//FloatToStrF(dAngle, AnsiString::sffGeneral, 5,2); } } } catch(EConvertError *EC) { bRet = false; if(m_bShowExeption == true) { S = pIndexEdit->Text; AnsiString Text = "¬ведено неправильное чиcловое значение '" + S + "'"; Application->MessageBox(_WST(Text),_WST("ќшибка"),MB_OK | MB_ICONEXCLAMATION); if(pIndexEdit->CanFocus()) pIndexEdit->SetFocus(); } } return bRet; }
Int32 CtrlAddItemToPanel_Edit(TWindow*pWin, TPanel* pPanel, Coord nX, Coord nY, Coord nWidth, Coord nHeight) { TEdit* pEdit = new TEdit(); Int32 nEditId = 0; if(pEdit->Create(pPanel)) { TRectangle obBtnRec(0,0,0,0); nEditId=pEdit->GetId(); obBtnRec.SetRect(nX, nY, nWidth, nHeight); pEdit->SetBounds(&obBtnRec); pEdit->SetMaxChars(20); pEdit->SetUnderline(TRUE); } return nEditId; }
//--------------------------------------------------------------------------- bool __fastcall InputDialog(const UnicodeString ACaption, const UnicodeString APrompt, UnicodeString & Value, UnicodeString HelpKeyword, TStrings * History, bool PathInput, TInputDialogInitialize OnInitialize) { bool Result = False; TInputDialogToken Token; TForm * Form = new TForm(GetFormOwner(), 0); // bypass the VCL streaming (for Salamander) try { // salam needs to override this in UseSystemSettings Form->Position = poOwnerFormCenter; SetCorrectFormParent(Form); UseSystemSettingsPre(Form); // this is what TCustomForm.Loaded does // Note that this is not needed as due to use of an alternative constructor above // we are already set to default font // See TMessageForm::Create for contrary Form->Font->Assign(Application->DefaultFont); Form->ParentFont = true; Token.OnInitialize = OnInitialize; Token.PathInput = PathInput; TNotifyEvent OnShow; ((TMethod *)&OnShow)->Data = &Token; ((TMethod *)&OnShow)->Code = InputDialogShow; Form->OnShow = OnShow; Form->Canvas->Font = Form->Font; Form->BorderStyle = bsDialog; Form->Caption = ACaption; Form->ClientWidth = ScaleByTextHeightRunTime(Form, 275); Form->ClientHeight = ScaleByTextHeightRunTime(Form, 102); if (!HelpKeyword.IsEmpty()) { Form->HelpKeyword = HelpKeyword; Form->BorderIcons = TBorderIcons(Form->BorderIcons) << biHelp; } TLabel * Prompt = new TLabel(Form); Prompt->Parent = Form; Prompt->AutoSize = True; Prompt->Left = ScaleByTextHeightRunTime(Form, 10); Prompt->Top = ScaleByTextHeightRunTime(Form, 13); Prompt->Caption = APrompt; TEdit * Edit; THistoryComboBox * HistoryCombo; if (History == NULL) { Edit = new TEdit(Form); Edit->Parent = Form; Edit->Text = Value; Edit->SelectAll(); Edit->MaxLength = 255; Token.Data.Edit = Edit; Token.EditControl = Edit; } else { HistoryCombo = new THistoryComboBox(Form); HistoryCombo->Parent = Form; HistoryCombo->Text = Value; HistoryCombo->SelectAll(); HistoryCombo->Items = History; HistoryCombo->MaxLength = 255; HistoryCombo->AutoComplete = false; Token.EditControl = HistoryCombo; } Token.EditControl->Left = Prompt->Left; Token.EditControl->Top = ScaleByTextHeightRunTime(Form, 30); Token.EditControl->Width = ScaleByTextHeightRunTime(Form, 255); Prompt->FocusControl = Token.EditControl; int ButtonTop = ScaleByTextHeightRunTime(Form, 66); int ButtonSpace = ScaleByTextHeightRunTime(Form, 6); TButton * Button; Button = new TButton(Form); Button->Parent = Form; Button->Caption = Vcl_Consts_SMsgDlgOK; Button->ModalResult = mrOk; Button->Default = True; int ButtonHeight = ScaleByTextHeightRunTime(Button, Button->Height); int ButtonWidth = ScaleByTextHeightRunTime(Button, Button->Width); int ButtonsStart; if (HelpKeyword.IsEmpty()) { ButtonsStart = (Form->ClientWidth / 2) - ButtonWidth - (ButtonSpace / 2); } else { ButtonsStart = (Form->ClientWidth / 2) - (3 * ButtonWidth / 2) - ButtonSpace; } Button->SetBounds(ButtonsStart, ButtonTop, ButtonWidth, ButtonHeight); Button = new TButton(Form); Button->Parent = Form; Button->Caption = Vcl_Consts_SMsgDlgCancel; Button->ModalResult = mrCancel; Button->Cancel = True; Button->SetBounds(ButtonsStart + ButtonWidth + ButtonSpace, ButtonTop, ButtonWidth, ButtonHeight); if (!HelpKeyword.IsEmpty()) { Button = new TButton(Form); Button->Parent = Form; Button->Caption = Vcl_Consts_SMsgDlgHelp; Button->ModalResult = mrNone; Button->SetBounds(ButtonsStart + 2 * (ButtonWidth + ButtonSpace), ButtonTop, ButtonWidth, ButtonHeight); TNotifyEvent OnClick; ((TMethod*)&OnClick)->Code = InputDialogHelp; Button->OnClick = OnClick; } UseSystemSettingsPost(Form); if (Form->ShowModal() == DefaultResult(Form)) { if (History != NULL) { HistoryCombo->SaveToHistory(); History->Assign(HistoryCombo->Items); Value = HistoryCombo->Text; } else { Value = Edit->Text; } Result = true; } } __finally { delete Form; } return Result; }
// // Paint routine for Window, Printer, and PrintPreview for a TEdit/TListBox client. // void poundsMDIChild::Paint (TDC& dc, BOOL, TRect& rect) { poundsApp *theApp = TYPESAFE_DOWNCAST(GetApplication(), poundsApp); if (theApp) { // Only paint if we're printing and we have something to paint, otherwise do nothing. if (theApp->Printing && theApp->Printer && !rect.IsEmpty()) { // Use pageSize to get the size of the window to render into. For a Window it's the client area, // for a printer it's the printer DC dimensions and for print preview it's the layout window. TSize pageSize(rect.right - rect.left, rect.bottom - rect.top); HFONT hFont = (HFONT)GetClientWindow()->GetWindowFont(); TFont font("Arial", -12); if (hFont == 0) dc.SelectObject(font); else dc.SelectObject(TFont(hFont)); TEXTMETRIC tm; int fHeight = (dc.GetTextMetrics(tm) == TRUE) ? tm.tmHeight + tm.tmExternalLeading : 10; // How many lines of this font can we fit on a page. int linesPerPage = MulDiv(pageSize.cy, 1, fHeight); if (linesPerPage) { TPrintDialog::TData &printerData = theApp->Printer->GetSetup(); int maxPg = 1; // Get the client class window (this is the contents we're going to print). TEdit *clientEditWindow /* = 0*/; TListBox *clientListWindow = 0; TWindow *clientUnknownWindow = 0; clientEditWindow = TYPESAFE_DOWNCAST(GetClientWindow(), TEdit); if (clientEditWindow) maxPg = ((clientEditWindow->GetNumLines() / linesPerPage) + 1.0); else { clientListWindow = TYPESAFE_DOWNCAST(GetClientWindow(), TListBox); if (clientListWindow) maxPg = ((clientListWindow->GetCount() / linesPerPage) + 1.0); else clientUnknownWindow = TYPESAFE_DOWNCAST(GetClientWindow(), TWindow); } // Compute the number of pages to print. printerData.MinPage = 1; printerData.MaxPage = maxPg; // Do the text stuff: int fromPage = printerData.FromPage == -1 ? 1 : printerData.FromPage; int toPage = printerData.ToPage == -1 ? 1 : printerData.ToPage; char buffer[255]; int currentPage = fromPage; while (currentPage <= toPage) { int startLine = (currentPage - 1) * linesPerPage; int lineIdx = 0; while (lineIdx < linesPerPage) { // If the string is no longer valid then there's nothing more to display. if (clientEditWindow) { if (!clientEditWindow->GetLine(buffer, sizeof(buffer), startLine + lineIdx)) break; } else if (clientListWindow) { if (clientListWindow->GetString(buffer, startLine + lineIdx) < 0) break; } else if (clientUnknownWindow) { clientUnknownWindow->Paint(dc, FALSE, rect); break; } dc.TabbedTextOut(TPoint(0, lineIdx * fHeight), buffer, lstrlen(buffer), 0, NULL, 0); lineIdx++; } currentPage++; } } } } }