AnsiCompare ?



  • Hallo zusammen,

    ich brauch da mal uere Hilfe.

    Ich habe mir etwas Code kopiert und frage mich, warum das AnsiCompare nicht geht.

    Ich möchte damit ein StringGrid sortieren.

    Leider bekomme ich immer diese Fehlermeldung:

    [bcc32 Fehler] FormMain.cpp(198): E2316 'AnsiCompare' ist kein Member von 'UnicodeString'
    Vollständiger Parser-Kontext
    FormMain.cpp(154): Analyse: void StringGridShellSort(TStringGrid *,int,int,bool)

    Hier ein kleiner Teil vom Code:

    else if (iSortType == SORT_STRINGS)
              {
                if ((blAsccending &&
                   pGrid->Cells[iCol][iRow].AnsiCompare(
                   pGrid->Cells[iCol][iRow+1]) > 0 )||
                   (!blAsccending &&
                   pGrid->Cells[iCol][iRow].AnsiCompare(
                   pGrid->Cells[iCol][iRow+1]) < 0))
                   blSwap = true;
    

    Gruß

    abcd



  • Irgendwie wäre es ja schlau gewesen, UnicodeString zu zeigen ...





  • //----------------------------------------------------------------------------
    // StringGridShellSort() sortiert den Inhalt eines TStringGrid
    // (ShellSort-Verfahren wird verwendet) by Peter Tuschik 
    //----------------------------------------------------------------------------
    // Übergabeparameter:
    //
    // TStringGrid* pGrid   - Zeiger auf die zu sortierende Tabelle
    // int iCol             - Index der Spalte, nach der sortiert werden soll
    // int ilSortType       - Art der Daten in der Spalte, folgende Werte möglich:
    //                        SORT_NUMERIC  : Zelleninhalt numerisch
    //                        SORT_DATETIME : Zellen mit Datumswerten
    //                        SORT_STRINGS  : Zellen mit Strings
    // bool blAsccending    - true für aufsteigende Sortierung, anderenfalls false
    //----------------------------------------------------------------------------
    void StringGridShellSort(TStringGrid *pGrid, int iCol,
      int iSortType, bool blAsccending)
    {
      int iOffset, iLimit, iRow, iSwitch;
      int anz = pGrid->RowCount;
      AnsiString sBuf;
                                            // Vergleichsoffset auf Mitte der
      iOffset = anz / 2;                    // Datenmenge initialisieren
    
      while (iOffset)                       // Loop bis Offset == 0
      {
        bool blSwap = false;
        iLimit = anz - iOffset;
        do
        {
           iSwitch = 0;                     // Assume no switches at this offset
           /* Compare elements and switch ones out of order. */
           for (iRow = 1; iRow < iLimit; iRow++)
           {
               if (iSortType == SORT_NUMERIC)
               {
                  if ((blAsccending &&
                      ConvertToDoubleDef(pGrid->Cells[iCol][iRow], MaxDouble) >
                      ConvertToDoubleDef(pGrid->Cells[iCol][iRow+iOffset], MaxDouble)) ||
                      (!blAsccending &&
                      ConvertToDoubleDef(pGrid->Cells[iCol][iRow], MaxDouble) <
                      ConvertToDoubleDef(pGrid->Cells[iCol][iRow+iOffset], MaxDouble)))
                      blSwap = true;
               }
               else if (iSortType == SORT_DATETIME)
               {
                 try
                 {
                  if ((blAsccending &&
                      (TDateTime)pGrid->Cells[iCol][iRow] >
                      (TDateTime)pGrid->Cells[iCol][iRow+iOffset]) ||
                      (!blAsccending &&
                      (TDateTime)pGrid->Cells[iCol][iRow] <
                      (TDateTime)pGrid->Cells[iCol][iRow+iOffset]))
                      blSwap = true;
                 }
                 catch(...) {;}
               }
               else if (iSortType == SORT_STRINGS)
               {
                  if ((blAsccending &&
                      pGrid->Cells[iCol][iRow].AnsiCompare(
                      pGrid->Cells[iCol][iRow+iOffset]) > 0 )||
                      (!blAsccending &&
                      pGrid->Cells[iCol][iRow].AnsiCompare(
                      pGrid->Cells[iCol][iRow+iOffset]) < 0))
                      blSwap = true;
               }
    
               if (blSwap)
               {
                  sBuf = pGrid->Rows[iRow]->Text;
                  pGrid->Rows[iRow]->Text = pGrid->Rows[iRow+iOffset]->Text;
                  pGrid->Rows[iRow+iOffset]->Text = sBuf;
                  iSwitch = iRow+1;
                  blSwap = false;
               }
           } /* For */
    
           /* Sort on next pass only to where last switch was made. */
           iLimit = iSwitch - iOffset;
        }
        while(iSwitch);
    
        /* No switches at last offset, try one half as big. */
        iOffset = iOffset / 2;
      } /*while */
    }
    


  • Weil diese bei UnicodeString (anstatt AnsiString) nur noch "Compare" heißt (s.a. Migrating legacy C++ Builder Apps to C++ Builder 10 Seattle ;-).

    PS: Deine Frage gehört in das VCL-Forum.



  • Es geht jetzt.

    Vielen Dank für die schnelle Hilfe.


Anmelden zum Antworten