Autor Beitrag
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Do 04.02.10 20:00 
Hi DF!

Ich stehe momentan vor einem für mich unlösbaren Problem. Ich habe im Programmverzeichnis ein INI-File, Setup.ini. Dieses File existiert DEFINITIV, aber ich bekomme jedes Mal eine Exception geworfen (verwende Windows 7):

ausblenden volle Höhe Delphi-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:
procedure TMainForm.FormCreate(Sender: TObject);
var Ini : TIniFile; PhraseCount : Integer;
  I: Integer;
begin
  try
   PerformSysCheck;
   // Ini öffnen
   ShowmEssage(ExtractFilePath(ParamStr(0))+'Setup.ini'); // alles ok mit dem Pfad
   if not FileExists(ExtractFilePath(ParamStr(0))+'Setup.ini'then
    raise Exception.Create('File not found');
   Ini := TIniFile.Create(ExtractFilePath(ParamStr(0))+'Setup.ini');
   // Zahl der Texte auslesen
   PhraseCount := Ini.ReadInteger('Options''PhraseCount', -1);
   SetLength(FPhrases, PhraseCount);
   // Texte auslesen
   for I := 0 to PhraseCount - 1 do
    FPhrases[I] := Ini.ReadString('Phrases', IntToStr(I), 'Error');
   // Rules.pas
   PageControl1.SelectNextPage(true, false);
   // Label-Array füllen
   SetLength(Labels, 8);
   Labels[0] := Welcome;
   Labels[1] := Sys_Check;
   Labels[2] := Setuptype;
   Labels[3] := Path;
   Labels[4] := Components;
   Labels[5] := Summary;
   Labels[6] := Install;
   Labels[7] := Lbl_ready;
  except
   ShowMessage(StrErrorDuringInit);
   Application.Terminate
  end;
end;


Was kann ich da machen?

_________________
Die Lösung ist nicht siebzehn.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 04.02.10 20:29 
Bekommst du die FileNotFound-Exception, oder eine andere? Ich vermute nämlich letzteres.

TIniFile verwendet ja die Windows-Inifile-API, und es kann gut sein, dass da unter Win7 mit den Zugriffsrechten was schiefläuft, wenn dein Programm im Programme-Ordner liegt (C:\program files\ ...).

Mit TMemIniFile sollte der (Lese)zugriff klappen, probier das mal aus.

_________________
We are, we were and will not be.
DonManfred
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148
Erhaltene Danke: 2

Windows 7
Delphi XE3 Pro + HTML5Builder
BeitragVerfasst: Fr 05.02.10 15:06 
user profile iconMitmischer 1703 hat folgendes geschrieben Zum zitierten Posting springen:
Hi DF!
ausblenden Delphi-Quelltext
1:
   ShowmEssage(ExtractFilePath(ParamStr(0))+'Setup.ini'); // alles ok mit dem Pfad					

Was kann ich da machen?


AFAIK ist ParamStr(0) der Pfad UND Dateiname der eigenen EXE... Demnach suchst Du also z.B. nach C:\Programme\Testprogramm\test.exeSetup.ini

Ungetestet; hab ich grad so im Kopf...

Ich hol mir den Pfad immer mit

ausblenden Delphi-Quelltext
1:
2:
3:
  own_path := ExtractFilePath(Application.ExeName);
  if own_path[Length(own_path)] <> '\' then
    own_path := own_path + '\';


Hope it helps

_________________
Gruss Manfred
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Fr 05.02.10 16:16 
nope. der extractfilepath ist schon korrekt.
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Fr 05.02.10 17:11 
Also ich benutze das auch immer so: ExtractFilePath(ParamStr(0))+'\data\data.dat'

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Fr 05.02.10 18:24 
ausblenden Delphi-Quelltext
1:
showmessage(extractFilePath(ParamStr(0)));					


liefert bei mir in Delphi 2010 ein Ergebnis MIT schließendem Backslash.
DonManfred
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148
Erhaltene Danke: 2

Windows 7
Delphi XE3 Pro + HTML5Builder
BeitragVerfasst: Fr 05.02.10 19:07 
user profile iconFinnO hat folgendes geschrieben Zum zitierten Posting springen:
nope. der extractfilepath ist schon korrekt.


Ok, kann durchaus sein, das ich den Code so in der Form schon seit Jahren (und über diverse Delphi-Versionen hinweg) benutze... Ich muss da mal probleme gehabt haben ;)
*nachguck* Yo, laut Doku (Delphi 2006) liefert ExtractFilePath den Pfad mit abschliessendem Backslash.

Dann wäre es interessant, WELCHE exception gemeldet wird (wurde weiter oben ja auch schonmal angefragt).

_________________
Gruss Manfred
Mitmischer 1703 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Fr 05.02.10 19:12 
Die geworfene Exception ist meine eigene ;)

Hab's vielleicht missverständlich ausgedrückt, aber ich werfe - wenn die INI nicht da ist eine Exception.

Und ich den Test rausfallen lasse, geht das Createn der INI gut - doch bei PhraseCount gibts den Default-Wert!

Hab meine INI mal hochgeladen - ist da was falsch?

Edit: Mom, glaub, ich hab meinen Fehler gefunden

Tatsächlich... Ich hatte "Erweiterungen bei bekannten Dateitypen ausblenden an" :wand:

Jetzt müsste der Code eig funzen, wenn nicht, meld ich mich nochmal!
Einloggen, um Attachments anzusehen!
_________________
Die Lösung ist nicht siebzehn.