//--------------------------------------------------------------------------- void __fastcall TRegisterFormClass::FormShow(TObject *Sender) { VM_START_WITHLEVEL(1) AnsiString HID = MD5(GetHardwareID()).UpperCase(); HIDEdit->Text = HID.SubString(1, 16) + "-" + HID.SubString(17, 16); VM_END }
//разбивает строку на несколько с учётом максимально допустимой ширины //str - исходная строка //AlignText - результирующий текст //Width - максимальная ширина void CTextAlign::StringAlign ( const AnsiString &str, TStrings *AlignText, int Width ) { if ( Width <= 0 ) { AlignText->Add ( str ); return; } if ( str.Length() <= Width ) { AlignText->Add ( str ); return; } AnsiString FirstPart = str.SubString ( 1, Width ); AnsiString LastPart = str.SubString ( Width + 1, str.Length() - Width ); int pos = FirstPart.LastDelimiter(" "); if ( pos == 0 ) { //если нет пробелов в строке AlignText->Add ( FirstPart ); StringAlign ( LastPart, AlignText, Width ); }else { AlignText->Add ( FirstPart.SubString ( 1, pos ) ); LastPart = FirstPart.SubString ( pos + 1, FirstPart.Length() - pos ) + LastPart; StringAlign ( LastPart, AlignText, Width ); } }
bool __fastcall TEntryForm::InValidDateTime(AnsiString label, TEditPlus *edit) { AnsiString ud = edit->Text; int n = ud.Length(); if (n == 14 && strspn(ud.c_str(), "0123456789") == 14) { try { int year = ud.SubString(1,4).ToInt(); int month = ud.SubString(5,2).ToInt(); int day = ud.SubString(7,2).ToInt(); int hour = ud.SubString(9,2).ToInt(); int min = ud.SubString(11,2).ToInt(); int sec = ud.SubString(13,2).ToInt(); TDateTime d(year, month, day); TDateTime t(hour, min, sec, 0); return false; } catch (...) {} } AnsiString msg = "The field "+label+" contains the value '"+edit->Text+"'." +" This is invalid for a non null datetime field."; Application->MessageBox(msg.c_str(), "Invalid DateTime", ID_OK); return true; }
//--------------------------------------------------------------------------- double __fastcall CNHB300::GetWeight() { char strReceive[300]={0}; AnsiString strMsg; AnsiString strMsgNew; if(ReadSizeData(strReceive)) { AnsiString strMsg=strReceive; int nPosStart=strMsg.AnsiPos("ST,"); int nPosEnd=strMsg.SubString(nPosStart,15).AnsiPos("g")+nPosStart-1; if(nPosStart>0 && nPosEnd>0 && (nPosEnd-nPosStart)>5) { strMsgNew=strMsg.SubString(nPosEnd-8,8); if(strMsgNew.AnsiPos("-")>0) { strMsgNew=strMsg.SubString(nPosEnd-7,7); return strMsgNew.ToDouble()*-1.0; } else return strMsgNew.ToDouble(); } else return -999.0; } else return -999.0; }
//--------------------------------------------------------------------------- TStringList* StringToTok2( AnsiString Words, AnsiString Dlmtr1, AnsiString Dlmtr2 ) { AnsiString Work = Words.Trim(); int spos; TStringList *Making = new TStringList; int spos1 = Work.AnsiPos(Dlmtr1); int spos2 = Work.AnsiPos(Dlmtr2); while (spos1 || spos2) { // int spos = 0; if (!spos1 && spos2) spos = spos2; else if (!spos2 && spos1) spos = spos1; else spos = (spos1 < spos2) ? spos1 : spos2; Making->Add(Work.SubString( 1, spos-1)); Work = Work.SubString( spos+1, Work.Length() - spos); Work = Work.Trim(); spos1 = Work.AnsiPos(Dlmtr1); spos2 = Work.AnsiPos(Dlmtr2); } // while if (Work != "") Making->Add(Work); return Making; }
//--------------------------------------------------------------------------- AnsiString GetPeriodStr(AnsiString Date1Str,AnsiString Date2Str) { // Convert date1 yyyy-mm-dd and date2 yyyy-mm-dd to "(September/February) yyyy - (September/February) yyyy" AnsiString Res=""; try { int y1=Date1Str.SubString(7,4).ToInt(), m1=Date1Str.SubString(4,2).ToInt(), d1=Date1Str.SubString(1,2).ToInt(), y2=Date2Str.SubString(7,4).ToInt(), m2=Date2Str.SubString(4,2).ToInt(), d2=Date2Str.SubString(1,2).ToInt(); switch (m1) { case 2: Res+="Февраль ";break; case 9: Res+="Сентябрь ";break; default: Res+="Unsupport ";break; } Res+=AnsiString(y1)+"г. -- "; switch (m2) { case 2: Res+="Февраль ";break; case 9: Res+="Сентябрь ";break; default: Res+="Unsupport ";break; } Res+=AnsiString(y2)+"г."; return Res; } catch(...) { Res="Unknown format of date"; return Res; } }
//--------------------------------------------------------------------------- void __fastcall TBolBB::TrataDadosRetorno(AnsiString Linha, int Registro, int &RegDet) { AnsiString IdLinha; if(Retorno.CNAB400 == true)//Padrão FEBRABAN/CNAB400 { IdLinha = Linha.SubString(1,1); if(IdLinha == "7") { IdLinha = "1"; rtNossoNumero[0] = 64; rtNossoNumero[1]= 17; rtMesOrigem[0] = 73; rtAnoOrigem[0] = 75; rtLancamentoFat[0] = 77; } } else//Padão FEBRABAN/CNAB240 { IdLinha = Linha.SubString(8,1); if(IdLinha == "3")//Registro detalhe { IdLinha = "1"; } } if(IdLinha == "1")//Registro Detalhes - Movimento { if(SetVariaveisRetorno(Linha,Registro)) ManutencaoRetorno(Registro); RegDet++; } }
//--------------------------------------------------------------------------- AnsiString __fastcall TBolBancoob::GetLinhaDigitavel(void) { GetNossoNumero(); AnsiString NossoNumeroComDV = NossoNumeroSemHifen; // Grupo 1 AnsiString Grupo1 = CodigoBanco + CodigoMoeda + Carteira; Grupo1 = Grupo1 + Agencia + CalculaDVLinhaDigitavel(Grupo1 + Agencia); // Grupo 2 AnsiString Grupo2 = "02" + CodigoCedente.SubString(1, 3); AnsiString Parte2 = CodigoCedente.SubString(4, 4) + NossoNumeroComDV.SubString(1, 1); Grupo2 = Grupo2 + Parte2 + CalculaDVLinhaDigitavel(Grupo2 + Parte2); // Grupo 3 AnsiString Grupo3 = NossoNumeroComDV.SubString(2, 5) + NossoNumeroComDV.SubString(7, 2); //Grupo3 = Grupo3 + TipoFaturamento + "01"; Substituído pela próxima Linha Grupo3 = Grupo3 + "001"; // Conforme Manual Sicoob/SC pág. 6 - Terceiro Grupo de Números - Posição 9 Grupo3 = Grupo3 + CalculaDVLinhaDigitavel(Grupo3); // Grupo 4 GetCodigoDeBarra(); // pra garantir que calculou o DVCodBarras AnsiString Grupo4 = DVCodBarras; // Grupo 5 AnsiString Grupo5 = FatorVencimento + ValorBoleto; ValidaLinhaDigitavel(Grupo1 + Grupo2 + Grupo3 + Grupo4 + Grupo5); return ( Grupo1 + Grupo2 + Grupo3 + Grupo4 + Grupo5 ); }
//--------------------------------------------------------------------------- AnsiString GetStrWithReplacedPoints(AnsiString Str, AnsiString PointStr=GetPointStr()) { AnsiString RetStr; int posPoint=Str.Pos(","); if (posPoint>0) RetStr=Str.SubString(1,posPoint-1)+PointStr+Str.SubString(posPoint+1,Str.Length()-posPoint); posPoint=Str.Pos("."); if (posPoint>0) RetStr=Str.SubString(1,posPoint-1)+PointStr+Str.SubString(posPoint+1,Str.Length()-posPoint); return RetStr; }
//--------------------------------------------------------------------------- AnsiString ReturnParsedDateInSQL(AnsiString Str) { // Date in format dd.mm.yyyy convert to yyyy-mm-dd AnsiString y=Str.SubString(7,4), m=Str.SubString(4,2), d=Str.SubString(1,2), date; date=y+"-"+m+"-"+d; return date; }
//--------------------------------------------------------------------------- AnsiString ReturnParsedDateInMask(AnsiString Str) { // Date in format yyyy-mm-dd convert to dd.mm.yyyy AnsiString y=Str.SubString(1,4), m=Str.SubString(6,2), d=Str.SubString(9,2), date; date=d+"."+m+"."+y; return date; }
void GetTCPClientConfigFromStr(const AnsiString& configure, AnsiString& ip, int& port) { int splitpos = configure.AnsiPos(","); if (splitpos > 0) { ip = configure.SubString(1, splitpos - 1); port = StrToInt(configure.SubString(splitpos+1, configure.Length())); } }
AnsiString __fastcall TFTPFile::GetUserName(AnsiString ServerString) { int pos = ServerString.LowerCase().Pos("ftp://"); if(pos < 1) return ""; ServerString = ServerString.SubString(pos + 6,ServerString.Length() - pos); pos = StrLScan(ServerString.c_str(),":"); if(pos < 0) return ""; return DecryFTPPassword(ServerString.SubString(1,pos)); }
//--------------------------------------------------------------------------- void StringToTokiensA( AnsiString Words, AnsiString Dlmtr, TStrings *Making ) { AnsiString Work = Words.Trim(); int spos; while ((spos = Work.AnsiPos(Dlmtr)) != 0) { Making->Add(Work.SubString( 1, spos-1)); Work = Work.SubString( spos+1, Work.Length() - spos); Work = Work.Trim(); } // while if (Work != "") Making->Add(Work); }
//const int max_count_line = 17; // кол-во строк в одном семестре //const int max_len_title = 35; //--------------------------------------------------------------------------- AnsiString TFormReportUchebKartStud::GetDateAsString(const AnsiString& str, bool isYear) { AnsiString res = ""; res += str.SubString(9,2); if (res.Length() == 1) res = "0" + res; res += " "; res += MounthNames[(str.SubString(6, 2).ToInt() - 1) % 12] + " "; res += str.SubString(1, 4); if (isYear) res += " г."; return res; }
void __fastcall TfrmMain::tcpServerExecute(TIdPeerThread *AThread) { TSimpleClient *Client; AnsiString Com; // System command AnsiString Msg; //Get the text sent from the client try { Msg = AThread->Connection->ReadLn("",5000); } catch (...) { } // Get the clients package info if (Msg.Length()==0)return; Client = (TSimpleClient *)(AThread->Data); // Check to see if the clients name has been assigned yet if (Client->Name == "Logging In") { // if not, assign the name and announce the client Client->Name = Msg; UpdateClientList(); BroadcastMessage("System", Msg + " has just logged in."); AThread->Connection->WriteLn(memEntry->Lines->Text); } else // If name is set, then send the message if (Msg[1] != '@') { // Not a system command BroadcastMessage(Client->Name, Msg); } else { // System command Com = UpperCase(Trim(Msg.SubString(2, Msg.Pos(":") -2))); Msg = UpperCase(Trim(Msg.SubString(Msg.Pos(":") +1, Msg.Length()))); if (Com == "CLIENTS") AThread->Connection->WriteLn( AnsiString("@") + AnsiString("clients:") + lbClients->Items->CommaText); if (Com == "KILL") KillClient(Msg); } }
//---------------------------------------------------------------------------- void TForm1::LeerPalabra(AnsiString linea, int &i,AnsiString &palabra) { palabra=""; while(linea.SubString(i,1)!= " " && linea.SubString(i,1)!= "" ) { palabra=palabra+linea.SubString(i,1); i++; } if (linea.SubString(i,1)== "")i++; }
AnsiString GenericUtils::ConvertPathCygwinToWindows(AnsiString original){ //In case of source path I have to fix the Drive letter as well if(original.Length() > 11 && original.Pos("/cygdrive/") == 1){ AnsiString driveLetter = original[11]; original = driveLetter + ":\\" + original.SubString(13, original.Length()); } AnsiString answer; //This loop fixes the spaces for(int i = 1; i <= original.Length(); i++){ if(i != original.Length() && original[i] == '\\' && original[i + 1] == ' '){ answer += ' '; i++; //Skip the next character since it is a space }else{ answer += original[i]; } } //Now fix the back slashes for(int i = 1; i <= answer.Length(); i++){ if(answer[i] == '/'){ answer[i] = '\\'; } } return answer; }
AnsiString GenericUtils::ConvertPathWindowsToCygwin(AnsiString original){ //In case of source path I have to fix the Drive letter as well AnsiString driveLetter = ExtractFileDrive(original); if(driveLetter != ""){ original = "/cygdrive/" + AnsiString(driveLetter[1]).LowerCase() + "/" + original.SubString(4, original.Length()); } AnsiString answer; for(int i = 1; i <= original.Length(); i++){ if(original[i] == '\\'){ original[i] = '/'; } } return original; /* for(int i = 1; i <= original.Length(); i++){ if(original[i] == ' '){ answer += "\\ "; }else{ answer += original[i]; } } return answer; */ }
//--------------------------------------------------------------------------- AnsiString __fastcall DirFromAbbr( AnsiString AbbrDir, AnsiString ProjDir ) // Получает имя директории из $(PRJ)\Obj (или типа того) { AbbrDir = ExcludeTrailingBackslash(AbbrDir); AnsiString Subs = AbbrDir.SubString( 1, 6); if (Subs == PrjDir) { AbbrDir.Delete(1,6); if (ProjDir == "") return ExtractFileDir(Project->NameOfFile) + AbbrDir; else return ProjDir + AbbrDir; } else if (Subs == MseDir) { char buff[301]; AbbrDir.Delete(1,6); if (GetMSEPathStr( pcProgram, buff, 300)) return buff + AbbrDir; return ExtractFileDir(Application->ExeName) + AbbrDir; } else if (Subs == DatDir) { char buff[301]; AbbrDir.Delete(1,6); if (GetMSEPathStr( pcData, buff, 300)) return buff + AbbrDir; return ExtractFileDir(Application->ExeName) + "\\Data" + AbbrDir; } else return AbbrDir; }
AnsiString TFrmPickVal::GetFilterStr(AnsiString Find) { AnsiString Allsfilter ,Sfilter =""; AnsiString TmpFind = Find; // if (FLocalText !="") // { // TmpFind = FLocalText +" " +TmpFind; // } if (TmpFind =="") Allsfilter =""; else { DynamicArray <AnsiString> StrArr; Split(TmpFind,StrArr,' '); for (int j=0;j<StrArr.Length;j++) { if (StrArr[j] =="") continue ; Sfilter =""; for (int i=0; i< dbgmaster->Columns->Count;i++) { // if (CdsMaster->Fields->Fields[i]->DataType ==ftString) // { Sfilter = Sfilter+" or "+dbgmaster->Columns->Items[i]->FieldName+ " like '%"+StrArr[j]+"%'"; // } } Sfilter =Sfilter.SubString(4,MaxInt); Allsfilter = Allsfilter+" and ("+ Sfilter+")"; } StrArr.Length = 0; Allsfilter =Allsfilter.SubString(5,MaxInt); } return Allsfilter; }
//--------------------------------------------------------------------------- /// Meotoda odpowiada za w³aœciwe wyszukiwanie danych opini, metoda przyjmuje znaczniki pocz¹tkowe oraz koñcowe, /// pomiêdzy którymi znajduj¹ siê po¿¹dane teksty. AnsiString __fastcall ParsujDane::ZnajdzTekstOpini(AnsiString &ATextOpini, AnsiString AZnacznikPocz, AnsiString AZnacznikKoniec, bool ATnij) { AnsiString txt; int pozycjaZnacznik, start, koniec; pozycjaZnacznik = ATextOpini.Pos(AZnacznikPocz); if (pozycjaZnacznik == 0) return ""; while (true) { txt += ATextOpini[pozycjaZnacznik]; if (ATnij) { if (txt.Pos(AZnacznikPocz) > 0) { txt = txt.Delete(1, AZnacznikPocz.Length()); } } if (txt.Pos(AZnacznikKoniec) > 0) break; pozycjaZnacznik++; } if (!ATnij) { start = AZnacznikPocz.Length() + 1; koniec = txt.Length() - AZnacznikPocz.Length() - AZnacznikKoniec.Length(); } else { start = 1; koniec = txt.Length() - AZnacznikKoniec.Length(); } txt = txt.SubString(start, koniec); txt.TrimLeft(); txt.TrimRight(); return txt; }
//--------------------------------------------------------------------------- TStringList* StringToTokiens( AnsiString Words, AnsiString Dlmtr ) { AnsiString Work = Words.Trim(); int spos; TStringList *Making = new TStringList; while ((spos = Work.AnsiPos(Dlmtr)) != 0) { Making->Add(Work.SubString( 1, spos-1)); Work = Work.SubString( spos+1, Work.Length() - spos); Work = Work.Trim(); } // while if (Work != "") Making->Add(Work); return Making; }
//--------------------------------------------------------------------------- bool __fastcall TRawPrint::ValidaComando(AnsiString Comando) { bool Retorno; AnsiString Parametro; int Indice = 1; int Valor; try { for(int i = 0; i < Comando.Length() / 3; i++)//Percorre o Comando { Parametro = Comando.SubString(Indice, 3); if(Indice < 4) Indice = Indice + 3 + i; else Indice = Indice + 3;//Índice de Início do Último Parâmetro (7) Valor = StrToIntDef(Parametro, -1); //Verifica se é Inteiro if(Valor >= 0 && Valor < 256) //Verifica se o Valor do Parâmetro está de acordo com Manual da Epson { Retorno = true; } else { Retorno = false; } } } catch(Exception & E) { Erro("Erro ao validar Comando informado no Texto.\r\n\r\n" + E.Message + "\r\n"); } return Retorno; };
// это таймер приема данных void __fastcall TForm1::Timer1Timer(TObject *Sender) { char ch; DWORD temp; if (!ReadFile(hPort, &ch, 1, &temp, NULL)) return; // читаем посимвольно if (ch!='\r') sRecString+=ch; // и ждем конца строки else { int index =sRecString.Pos("Card Out"); // пришло сообщение о извлечении карты if (index!=0) // ну может имеет смысл это убрать все это. чтоб стабилнее работало { mLog->Lines->Add("get Card Out"); CurCardLost(); } index = sRecString.Pos("CurCard"); // CurCard - это префикс такой if (index==0) { sRecString=""; return; } AnsiString sNewCardID; sNewCardID=sRecString.SubString(index+8,sRecString.Length()-index-7); sRecString=""; if (sNewCardID!=lCurCardID->Caption) NewCardFound(sNewCardID); bGetCardFlag=true; } }
//--------------------------------------------------------------------------- // 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)
//--------------------------------------------------------------------------- void SetDisplayLabels(TIBQuery * query, TcxGridDBDataController * DataController, AnsiString str) { if(!IsConnected()) return; int last_index = 1; int count = 0; AnsiString item; int length = str.Length(); for(int i = 1;i<=length; i++) { if(str[i] == ',' || i == length ) { int len = i-last_index; if(i == length) len = i-last_index+1; item = str.SubString(last_index, len); last_index = i+1; if(count <= query->FieldList->Count-1) query->FieldList->Fields[count]->DisplayLabel = item; item = item.Trim(); if(item == "false") query->FieldList->Fields[count]->Visible = false; count ++; } } if(query->Active && DataController->ItemCount == 0) DataController->CreateAllItems(); }
//--------------------------------------------------------------------------- void __fastcall TfrmClimateAM::FormShow(TObject *Sender) { int cant=AnsiString(condTemp->FileName).Length(); if (cant==0) { } else { int existe=access(condTemp->FileName, 0); if(existe==-1) // el archivo no existe { Application->MessageBox("The specified file does not exist!!!","¡Advertencia!",MB_OK); return; } else { FileData *util=new FileData(); AnsiString nombre = AnsiString(condTemp->FileName); int posicion=nombre.Pos("."); int longitud=nombre.Length(); int caract=longitud-posicion; AnsiString ext=nombre.SubString(posicion+1,caract); if(ext=="prn") num=util->GetFieldsName(List,condTemp->FileName); if(ext=="csv") num=util->GetFieldsNameFromCSVFile(List,condTemp->FileName); delete util; } } PutValuesOnForm(); }
//--------------------------------------------------------------------------- AnsiString __fastcall GetMatlab6Root(void) { AnsiString S = ""; __TRY TRegistry *RR = new TRegistry(); try { // Для Matlab 6.5 RR->RootKey = HKEY_CLASSES_ROOT; if (RR->OpenKey("\\Matlab.Application.Single.6\\CLSID",false)) S = RR->ReadString(""); if (RR->OpenKey("\\CLSID\\"+S+"\\LocalServer32",false)) S = RR->ReadString(""); int ps = S.AnsiPos("matlab.exe"); if (ps) { S = S.SubString( 1, ps-2); // S содержит размещение matlab.exe (полный путь) S = ExtractFileDir(S); S = ExtractFileDir(S); } } __finally { delete RR; } if (!DirectoryExists(S)) { S = ""; } __CATCH return S; }
bool TAnimModel::Init(AnsiString asName, AnsiString asReplacableTexture) { if (asReplacableTexture.SubString(1, 1) == "*") // od gwiazdki zaczynaj� si� teksty na wy�wietlaczach asText = asReplacableTexture.SubString(2, asReplacableTexture.Length() - 1); // zapami�tanie tekstu else if (asReplacableTexture != "none") ReplacableSkinId[1] = TTexturesManager::GetTextureID(NULL, NULL, asReplacableTexture.c_str()); if (TTexturesManager::GetAlpha(ReplacableSkinId[1])) iTexAlpha = 0x31310031; // tekstura z kana�em alfa - nie renderowa� w cyklu nieprzezroczystych else iTexAlpha = 0x30300030; // tekstura nieprzezroczysta - nie renderowa� w cyklu // przezroczystych return (Init(TModelsManager::GetModel(asName.c_str()))); }