Autor Beitrag
Blamaster
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Di 28.08.07 17:21 
Hi,

Das Programm wird von Delphi so normal erstellt, Delphi gibt also keinen Fehler aus. Dafür aber die Exe wenn ich sie starten möchte.

Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.FormCreate(Sender: TObject);
begin
if not Fileexists('einstellungen.ini'then
begin
Form2.Show;
end;
ini := TIniFile.Create(ExtractFilePath(ParamStr(0))+'einstellungen.ini');
try
Winrar:= ini.ReadString('Optionen','Winrar','');
Archivpfad:= ini.ReadString('Optionen','Archivpfad','');
finally
ini.Free;
if Fileexists(Archivpfad+'pw.txt')then
begin
ListBox1.Items.LoadFromFile(Archivpfad+'pw.txt');
end;
GetFilesInDirectory(Archivpfad, '*.rar*', Listbox2.Items, False, True);
end;
end;


Das soll erstmal bewerkstelligen, das wenn das Ini file noch nicht existiert er erstmal nicht weiter macht sondern Form2 anzeigt.
Wie kann ich ihm nun sagen das er wirklich erst irgendwas laden darf wenn das Ini file existiert ?
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Di 28.08.07 17:31 
1. Aussagekräftige Überschrift
2. Mehr Quellcode, Variablendefinitonen usw.
3. Fehlermeldung...
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Di 28.08.07 17:35 
Zitat:
Wie kann ich ihm nun sagen das er wirklich erst irgendwas laden darf wenn das Ini file existiert ?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm1.FormCreate(Sender: TObject); 
begin 
  if Fileexists('einstellungen.ini'then 
    begin 
      ini := TIniFile.Create(ExtractFilePath(ParamStr(0))+'einstellungen.ini'); 
      try 
        Winrar := ini.ReadString('Optionen','Winrar',''); 
        Archivpfad := ini.ReadString('Optionen','Archivpfad',''); 
      finally 
        ini.Free;
      end
      if Fileexists(Archivpfad+'pw.txt')then 
        ListBox1.Items.LoadFromFile(Archivpfad+'pw.txt'); 
      GetFilesInDirectory(Archivpfad, '*.rar*', Listbox2.Items, False, True); 
    end else 
    begin
      Form2.Show;
      exit; // <-- muss nicht rein, würde sowieso passieren
    end
end;


Ansonsten würde ich mir an deiner Stelle angewöhnen den Code an entsprechenden Stellen einzurücken. Sieht so nicht nur besser aus, sondern wird auch übersichtlicher (bei deinen begin und end ist z.B. das end von try/finally an der falschen Stelle gelandet).

Gruß

Calculon
--
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 28.08.07 18:10 
ausblenden Delphi-Quelltext
1:
if not Fileexists('einstellungen.ini'then					

Diese Abfrage prüft, ob es die Datei C:\Windows\einstellungen.ini gibt. Da du deine Datei nicht ins Windows-Verzeichnis speicherst, wird diese Abfrage immer True ergeben.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Blamaster Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Di 28.08.07 18:12 
Auch mit Calculons code geht es nicht folgender Error kommt:

Project Project2.exe raised excaption class EAccessViolation with message 'Access violation at adress 00452CDE in module Project2.exe'. Read of adress 000002F4'. Process stopped. Use Step or Run to continue.

Der rest vom code ist meiner Meinung nacher eher unwichtig denn wenn ich die prozedur

if not FileExists weg mache, läuft das Programm ohne Fehler.
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Di 28.08.07 18:18 
Wie bereits gesagt, keine relative Pfade, also FileExists(...) korrigieren

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Blamaster Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Di 28.08.07 18:25 
Aber auch mit Direkter Pfadangabe kommt der Fehler.

Delphi makiert dann in der Unit folgende Zeile blau:

Application.CreateForm(TForm2, Form2);

Edit. Ich hab jetzt mal die ini Datei selber erstellt. Jetzt kann ich das Programm ganz normal starten und auch über den Optionen Button Form2 öffnen.

Er scheint also nen Problem damit zu haben gleich am Anfang form2 auf zu machen.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 28.08.07 18:39 
Logisch, wenn du das OnCreate von Form1 benutzt, existiert Form2 noch gar nicht. Nimm lieber OnShow.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Di 28.08.07 18:42 
(a) die Zeile sehe ich in Deinen Quellen nicht
(b) Du solltest natürlich erst Form2 erstellen, ehe Du sie in deiner Proc der Form1 per Form2.Show anzeigst
(c) Gibt es dort irgendeinen Überkreuzbezug?

[EDIT]

zu laaaaaaaaaaaaaaaaaannnnnnnnnnnnnnnnnggggggggggsssssssssaaaaaaaaammmmm
und
zu blind

:cry: :cry:

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Blamaster Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Di 28.08.07 18:45 
Hi hört sich gut an wo soll den Form Show hin ?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 28.08.07 18:46 
Im Objektinspektor von Form1 Doppelklick auf OnShow.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Blamaster Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Di 28.08.07 18:54 
Und was soll dann ins FormShow auf Form1 rein ?

Alles was jetzt in FormCreate steht ?
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Di 28.08.07 19:32 
*auch mal was beantworten und nicht immer nur meckern will*
Jap...
Blamaster Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Di 28.08.07 19:55 
Jetzt gehts. 1000 Dank euch allen. :)