//--------------------------------------------------------------------------- void __fastcall TFormDaltonista::ButtonStartClick(TObject *Sender) { LabeledEditPunkty->Tag=0; LabeledEditPunkty->Text=0; LabeledEditGapa->Tag=0; LabeledEditGapa->Text=0; Shape->Brush->Color=clWhite; if(!TryStrToInt(EditStart->Text,EditStart->Tag)||EditStart->Tag<1) { MessageDlg("Bledne dane",mtError,TMsgDlgButtons()<<mbOK,0); EditStart->Text=20; } else { TimerZegar->Enabled=(TimerZegar->Enabled==false); if(TimerZegar->Enabled) { ButtonStart->Caption="Stop"; EditStart->ReadOnly=true; } else { ButtonStart->Caption="Start"; EditStart->ReadOnly=false; } } }
__int64 ToInt(const UnicodeString & Value) { __int64 Result = 0; if (TryStrToInt(Value, Result)) { return Result; } else { return 0; } }
//--------------------------------------------------------------------------- intptr_t StrToInt(const UnicodeString & Value) { __int64 Result = 0; if (TryStrToInt(Value, Result)) { return static_cast<intptr_t>(Result); } else { return 0; } }
__int64 StrToInt64Def(const UnicodeString & Value, __int64 DefVal) { __int64 Result = DefVal; if (TryStrToInt(Value, Result)) { return Result; } else { return DefVal; } }
intptr_t StrToIntDef(const UnicodeString & Value, intptr_t DefVal) { __int64 Result = DefVal; if (TryStrToInt(Value, Result)) { return static_cast<intptr_t>(Result); } else { return DefVal; } }
//Начало ввода и проверки правильности ввода переменной d типа long int(integer) void __fastcall TForm1::Edit2Change(TObject *Sender) { if ((TryStrToInt(Edit2->Text,d)) & (d >= -2147483638) & (d <= 2147483647)) { Panel2->Caption = "Число d введено правильно"; countd = true; } else { Panel2->Caption = "Неправильно введено число d"; countd = false; } }
//Начало ввода и проверки правильности ввода переменной c типа long int(integer) void __fastcall TForm1::Edit1Change(TObject *Sender) { if ((TryStrToInt(Edit1->Text,c)) & (c >= -2147483638) & (c <= 2147483647)) { Panel1->Caption = "Число c введено правильно"; countc = true; } else { Panel1->Caption = "Неправильно введено число c"; countc = false; } }
void __fastcall TObjFrm::SetAsString(int n,String val) { if (CompList->Items[n]) { TCustomEdit *m=dynamic_cast<TCustomEdit*>((TObject*)CompList->Items[n]); if (m) { m->Text=val; } else { int i; if (TryStrToInt(val, i)) { SetAsInt(n, i); } } } }
//Начало ввода и проверки правильности ввода переменной k типа integer void __fastcall TForm1::Edit1Change(TObject *Sender) { if ((TryStrToInt(Edit1->Text,k32)) & ((k32 >= 1) & (k32 <= 255))) { k = k32; Panel1->Caption = "Число k введено правильно"; countk = true; } else { Panel1->Caption = "Неправильно введено число k"; countk = false; } }
//Начало ввода и проверки правильности ввода переменной n типа integer void __fastcall TForm1::Edit3Change(TObject *Sender) { if ((TryStrToInt(Edit3->Text,n32)) & ((n32 >= 1) & (n32 <= 255))) { n = n32; Panel3->Caption = "Число n введено правильно"; countn = true; } else { Panel3->Caption = "Неправильно введено число n"; countn = false; } }
//--------------------------------------------------------------------------- void __fastcall LoadListViewStr(TListView * ListView, UnicodeString ALayoutStr) { UnicodeString LayoutStr = ::CutToChar(ALayoutStr, L';', true); int PixelsPerInch = LoadPixelsPerInch(::CutToChar(ALayoutStr, L';', true)); int Index = 0; while (!LayoutStr.IsEmpty() && (Index < ListView->Columns->Count)) { int Width; if (TryStrToInt(::CutToChar(LayoutStr, L',', true), Width)) { ListView->Column[Index]->Width = LoadDimension(Width, PixelsPerInch); } Index++; } }
//--------------------------------------------------------------------------- // Split a NBD connection string (host:port) into the host and port parts. // bool __fastcall SplitConnectionString(AnsiString ConnectionString, AnsiString &HostPart, int &PortPart) { AnsiString sHost; int nPort = 0, nPortPos; nPortPos = ConnectionString.Pos(":") + 1; if (nPortPos) { sHost = ConnectionString.SubString(1,nPortPos - 2); if (TryStrToInt(ConnectionString.SubString(nPortPos, ConnectionString.Length() - nPortPos + 1), nPort) && nPort > 0 && nPort < 65536) { HostPart = sHost; PortPart = nPort; return true; } // if (port number is valid) } // if (nPortPos) return false; } // bool __fastcall SplitConnectionString(AnsiString ConnectionString, AnsiString &HostPart, int &PortPart)
static bool TryGetSpeedLimit(const UnicodeString & Text, uintptr_t & Speed) { bool Result; if (AnsiSameText(Text, LoadStr(SPEED_UNLIMITED))) { Speed = 0; Result = true; } else { int64_t SSpeed; Result = TryStrToInt(Text, SSpeed) && (SSpeed >= 0); if (Result) { Speed = SSpeed * 1024; } } return Result; }
//Начало ввода элементов массива void __fastcall TForm1::Button2Click(TObject *Sender) { if (countn == true) { if (i != n) { if ((TryStrToInt(Edit4->Text,randmas)) & (randmas >= -2147483638) & (randmas <= 2147483647)) { array[i] = randmas; Panel4->Caption = array[i]; i = i+1; Edit4->Text = " "; if (i == n) countarray = true; } else Panel4->Caption = "Элемент массива введен не верно"; } else Panel4->Caption = "Введены все эелементы массива"; } else Panel4->Caption = "Значение n введено не верно"; }