Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi AnsiIndexText() funktioniert nicht (https://www.delphipraxis.net/89682-ansiindextext-funktioniert-nicht.html)

DoktorD 4. Apr 2007 07:52


AnsiIndexText() funktioniert nicht
 
Hi alle zusammen. Ich bin am verzweifeln. Und zwar funktioniert mein AnsiIndexText() irgendwie nicht, obwohl ich diese Funktion schon öfters benutzt habe.

hier mein Code:
Delphi-Quellcode:
INItext := IniFileGetVal(_strSectionName, _strBaud, '0');
      case AnsiIndexText(INItext, ['1200', '2400', '4800', '9600', '19200', '38400', '57600', '115200']) of
      0: Baudrate := 1;
      1: Baudrate := 2;
      2: Baudrate := 3;
      3: Baudrate := 4;
      4: Baudrate := 5;
      5: Baudrate := 6;
      6: Baudrate := 7;
      7: Baudrate := 8;
      else
      bReturn := False;
      end;
Ich lese aus einem Inifile zunächst den String (INItext) aus. In diesem Fall z.B. eine '2400'. Wenn ich jedoch Debugge geht er sofort aus der Funktion raus, ohne bei 1: die Baudrate zu setzen.

Woran kann das liegen?

Die Muhkuh 4. Apr 2007 07:57

Re: AnsiIndexText() funktioniert nicht
 
Hi DoktorD,

bist Du sicher, dass auch wirklich nur z.B. 2400 drin steht?

Du könntest mal noch ein Trim einfügen:

Delphi-Quellcode:
case AnsiIndexText(Trim(INItext), ['1200', '2400', '4800', '9600', '19200', '38400', '57600', '115200']) of

DoktorD 4. Apr 2007 08:00

Re: AnsiIndexText() funktioniert nicht
 
Habs mal mit Trim() probiert, geht aber auch nicht in die Funktion. Der String ist ausgelesen worden und hat den jeweiligen Wert.

Hast du vielleich noch eine Idee?

Danke für die schnelle Antwort

Die Muhkuh 4. Apr 2007 08:05

Re: AnsiIndexText() funktioniert nicht
 
Mag jetzt vielleicht blöd klingen, aber versuch das hier mal, hatte mir bei etwas ähnlichem auch schon mal geholfen:

Delphi-Quellcode:
case AnsiIndexText(Trim(IntToStr(StrToInt(INItext))), ['1200', '2400', '4800', '9600', '19200', '38400', '57600', '115200']) of

DoktorD 4. Apr 2007 08:19

Re: AnsiIndexText() funktioniert nicht
 
Habe eben nochmal rumgespielt und nun hab ich irgendwie hinbekommen, aber ich verstehe das irgendwie noch nicht.

Also wenn ich es so mache gehts:
Delphi-Quellcode:
var
  INIText : String;
  ComPort : Integer;
begin
      INItext := '3';
      case AnsiIndexText((INItext), ['1', '2', '3', '4', '5', '6', '7', '8', '9']) of
      0: ComPort := 1;
      1: ComPort := 2;
      2: ComPort := 3;
      3: ComPort := 4;
      4: ComPort := 5;
      5: ComPort := 6;
      6: ComPort := 7;
      7: ComPort := 8;
      8: ComPort := 9;
      end;
   Label1.Caption := IntToStr(ComPort);
end;

und wenn ich es so mache nicht:

Delphi-Quellcode:
var
  INIText : String;
  ComPort : Integer;
begin
      INItext := '3';
      case AnsiIndexText((INItext), ['1', '2', '3', '4', '5', '6', '7', '8', '9']) of
      0: ComPort := 1;
      1: ComPort := 2;
      2: ComPort := 3;
      3: ComPort := 4;
      4: ComPort := 5;
      5: ComPort := 6;
      6: ComPort := 7;
      7: ComPort := 8;
      8: ComPort := 9;
      end;
   //Label1.Caption := IntToStr(ComPort);
end;
Geht das nur, wenn ich den Integerwert ComPort verwende? Weil wenn ich ihn weglasse gehts nicht.

Die Muhkuh 4. Apr 2007 08:23

Re: AnsiIndexText() funktioniert nicht
 
Das ist möglich. Wenn es nicht gebraucht wird, wird aus rausoptimiert.

Du kannst ja mal schauen, ob vor den Codezeilen, also am Rand, kleine blaue Punkte sind. Wenn nein -> wirds rausoptimiert.

DoktorD 4. Apr 2007 11:17

Re: AnsiIndexText() funktioniert nicht
 
Ist tatsächlich so. Wusste ich auch noch nicht. Danke


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:32 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz