Autor Beitrag
FSS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Sa 01.07.06 10:00 
Hallo,
ich habe ein Problem mit meinem Code aber ich finde den Fehler nicht.

Ich habe folgende Variablen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Ini: TInifile;
user1:String;
user2:String;
user3:String;
user4:String;
user5:String;
user6:String;
user7:String;
user8:String;
user9:String;
user10:String;


Nun lese ich Informationen aus einem Ini-File aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Ini:=TIniFile.Create(ExtractFilePath(Application.ExeName) + 'd_ini\user.ini');
user1:=Ini.ReadString('check','1','');
user2:=Ini.ReadString('check','2','');
user3:=Ini.ReadString('check','3','');
user4:=Ini.ReadString('check','4','');
user5:=Ini.ReadString('check','5','');
user6:=Ini.ReadString('check','6','');
user7:=Ini.ReadString('check','7','');
user8:=Ini.ReadString('check','8','');
user9:=Ini.ReadString('check','9','');
user10:=Ini.ReadString('check','10','');
Ini.Free;


1-10 können entweder den Wert "true" oser "false" haben. Und danach soll das Programm jetzt suchen und dementsprechend Aufgaben ausführen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
if user1='true' then
begin
CheckBox1.Checked:=True;
Ini:=TIniFile.Create(ExtractFilePath(Application.ExeName) + 'd_ini\user.ini');
Edit1.Text:=Ini.ReadString('User','1','');
Edit_1.Text:=Ini.ReadString('Names','1','');
Ini.Free;
end else if user1='false' then
Edit1.Text:='';
Edit_1.Text:='';
CheckBox1.Checked:=False;
end;


Und hier gibt es jetzt ein Problem. Wenn der Wert im Ini-File "true" ist, wird die CheckBox nicht auf True gesetzt, außerdem wird der Wert bei [Names] nicht ausgelesen. Der Wert bei [User] wird aber ohne Probleme ausgelesen.

Fällt jemandem mein Fehler auf?

FSS
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 01.07.06 10:09 
Ohne die ini gesehen zu haben, wirds schwer. Kann da die Groß- und Kleinschreibung mit reinspielen?

Desweiteren würde ich dir für User1-10 empfehlen, doch eher über boolean und ReadBool zu gehen, oder zumindest in ReadString den Default Wert auf "false" oder "true" zu stellen und nicht auf "".

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
FSS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Sa 01.07.06 10:15 
Hier ist mal der Inhalt der Ini-Datei:

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
[User]
1=Testuser1
2=Testuser2
3=Testuser3
4=Testuser4
5=Testuser5
6=Testuser6
7=Testuser7
8=Testuser8
9=Testuser9
10=Testuser10

[Names]
1=Name1
2=Name2
3=Name3
4=Name4
5=Name5
6=Name6
7=Name7
8=Name8
9=Name9
10=Name10

[check]
1=true
2=true
3=true
4=false
5=false
6=false
7=false
8=false
9=false
10=false
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Sa 01.07.06 12:27 
Hallo,

ausblenden Delphi-Quelltext
1:
2:
      Edit_1.Text:='';  
      CheckBox1.Checked:=False;
werden immer ausgeführt, in Deinem Code fehlt ein begin end-Block.
Deshalb meinst Du das Names nicht ausgelesen wird, gelesen wird es schon,
aber wieder mit einem Leerstring überschrieben.

Auerdem kann man if user1='false' then weglassen, da der else-Zweig ausgeführt wird wenn if user1='true' then nicht zutrifft.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
if user1='true' then  
  begin  
  CheckBox1.Checked:=True;  
  Ini:=TIniFile.Create(ExtractFilePath(Application.ExeName) + 'd_ini\user.ini');  
  Edit1.Text:=Ini.ReadString('User','1','');  
  Edit_1.Text:=Ini.ReadString('Names','1','');  
  Ini.Free;  
  end 
  else 
    begin  
    Edit1.Text:='';  
    Edit_1.Text:='';  
    CheckBox1.Checked:=False; 
    end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Hobby-Programmierer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 238
Erhaltene Danke: 4

Win XP Pro, Vista Ultimate Trial :o)
D6 Pro, D7 Pro, Turbo, XE SE
BeitragVerfasst: Sa 01.07.06 12:48 
Tach ..., :)
oder vielleicht so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
CheckBox1.Checked:= (user1 = 'true');

if CheckBox1.Checked then begin  
  Ini:= TIniFile.Create(ExtractFilePath(Application.ExeName) + 'd_ini\user.ini');  
  Edit1.Text:= Ini.ReadString('User','1','');  
  Edit_1.Text:= Ini.ReadString('Names','1','');  
  Ini.Free;  
 end else begin  
  Edit1.Text:='';  
  Edit_1.Text:='';  
end;


Mich pers. stört aber der Aufbau der Ini. Anbei mein Vorschlag, so hast Du auf einen Blick sämtliche Angaben zu den Usern.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
[Liste]
1=Testuser1
2=Testuser2
...

[Testuser1]
Name= Name1
check= true

[Testuser2]
Name= Name2
check= false

usw.


Anm.: Wichtig ist aber zwangsläufig die Gross\Kleinschreibung der Parameter in der Ini !

LG Mario
[edit] Fehler bereinigt
FSS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Sa 01.07.06 14:41 
Tja,

ich habe jetzt eure Varianten ausprobiert, aber das Problem besteht weiterhin.

Ich werde das Ganze jetzt vermutlich nochmal komplett von Vorne anfangen.

Trotzdem Danke!
FSS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Sa 01.07.06 15:27 
Ok,

ich habe es nochmal komplett überarbeitet und jetzt funktioniert es.
Der Code ist jetzt außerdem kürzer und wohl auch säuberer!