switch



  • Ich habe eine switch Anweisung geschrieben und der Compiler sagt mir nun:
    Case bypasses initialization of a local variable

    Was hat das zu bedeuten??



  • Hallo.
    Warum postest du den Code nicht mal?
    Dann hätten wir es garantiert ein bisschen einfacher...
    MFG Aoeke



  • Okay: Baer bitte nicht über den restlichen Code meckern!

    Also:

    switch (httpcliCheck)
           {
                    case  '1':
    
                    if (HttpCli1->RcvdStream)
                    {
                            delete HttpCli1->RcvdStream;
                            HttpCli1->RcvdStream = NULL;
    
                    }
                    CheckForm->HTTPCmpCheck1->Caption = "false";
                    //download starten
                    Downloads->ToDownloadFiles->Items->Delete(ix);
                    Downloads->CGauge1->Visible = true;
                    Downloads->Stat1->Visible = true;
                    Downloads->Label1->Visible = true;
                    Downloads->Label2->Visible = true;
                    Downloads->Label1->Caption = MegaFileName;
                    Downloads->Image1->Visible = true;
    
                    AnsiString Downloadf1 = MegaLinkFinal;
    
                    try
                    {
                      HttpCli1->URL = Downloadf1;
                       Downloads->Stat1->Caption= ("connecting...");
                            HttpCli1->Get();
                    }
                    catch(...)
                    {
                       //   ShowMessage("Fatal Error at Link: " + Downloadf );
                    }
                    break;
    
                    case '2':
    
                    if (HttpCli2->RcvdStream)
                    {
                            delete HttpCli2->RcvdStream;
                            HttpCli2->RcvdStream = NULL;
    
                    }
                    CheckForm->HTTPCmpCheck2->Caption = "false";
                    //download starten
                    Downloads->ToDownloadFiles->Items->Delete(ix);
                    Downloads->CGauge2->Visible = true;
                    Downloads->Stat2->Visible = true;
                    Downloads->Label3->Visible = true;
                    Downloads->Label4->Visible = true;
                    Downloads->Label4->Caption = MegaFileName;
                    Downloads->Image2->Visible = true;
    
                    AnsiString Downloadf2 = MegaLinkFinal;
    
                  try
                  {
                    HttpCli2->URL = Downloadf2;
                    Downloads->Stat2->Caption= ("connecting...");
                    HttpCli2->Get();
                  }
                  catch(...)
                  {
                   // ShowMessage("Fatal Error at Link: " + Downloadf );
                  }
                  break;
       }
    

    Der meckert nur beim Zweiten Case!

    [ Dieser Beitrag wurde am 02.03.2003 um 19:54 Uhr von ratfury editiert. ]



  • Setzt mal Klammern bei den Cases.
    Also:

    switch (index)
    {
       case 1: {break;}
       case 2: {break;}
    }
    

    XDVD



  • ach ne, sowas - jetzt gehts!das hätte mir die borland hifle auch mal sagen können! Danke!



  • Auch wenn es jetzt "geht", das funktioniert bestimmt nicht so, wie du dir das erhofft hast. Denn sobald du die switch/case-Konstruktion verlässt sind deine Strings Downloadf1 und Downloadf2 wieder unbekannt/ungültig. Und genau darauf wollte dich der Compiler hinweisen.

    Und wenn du jetzt sagst, die Strings werden nur innerhalb des switch/case benötigt: wozu führst du dann überhaupt eine neue Variable ein, anstatt gleich MegaLinkFinal zu benutzen?



  • hmm, da hast du eigentlich recht das ist noch vom testen iregdnwie hab ich die noch nicht rausgenommen, weis auch nicht wieso... Danke für den Tipp!


Anmelden zum Antworten