Autor Beitrag
JayK
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Sa 25.06.05 18:10 
Hallo,

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
unit Unit1;
uses IniFiles, Unit2;
var ini: TIniFile;

procedure TForm1.FormCreate(Sender: TObject);
begin
    ini := TIniFile.Create(AppDataDir + '\SysIcon\Settings.ini');
    if FileExists(AppDataDir + '\SysIcon\Settings.ini') then
      begin
      Pref.RequestSave.Checked := ini.ReadBool('General', 'RequestSave', true);
      Pref.BrowseDialog.ItemIndex := ini.ReadInteger('General', 'BrowseDialog', 0);
      end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ini.WriteBool('General', 'RequestSave', Pref.RequestSave.Checked);
  ini.WriteInteger('General', 'BrowseDialog', Pref.BrowseDialog.ItemIndex);
  ini.Free;
end;

AppDataDir ist eine Funktion, die das Anwendungsdaten-Verzeichnis des Benutzers zurückgibt (C:\Dokumente und Einstellungen\<Benutzername>\Anwendungsdaten).
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
unit Unit2;
interface
type
  TPref = class(TForm)
  RequestSave: TJvCheckBox;
  BrowseDialog: TJvRadioGroup;
  end;

Immer, wenn er im FormClose am WriteInteger vorbeikommt, sagt er: In 'C:\Dokumente......\Anwendungsdaten\SysIcon\Settings.ini' kann nicht geschrieben werden.

Was soll das, frage ich mich jetzt? Erst alles erstellen (Create) und Booleanschreiben und dann meckern! :evil: Ich habe nachgeschaut: Die Ini-Datei ist nicht da!!! :evil: :evil: Noch nichtmal der Ordner!

Was muss ich tuen?

Schonmal Danke im vorraus,
JayK
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 25.06.05 18:16 
Hallo!

Das wird daran liegen, dass das Verzeichnis nicht existiert. Das wird nämlich nicht automatisch erstellt. Und ich habe das gerade mal ausprobiert, er mosert schon WriteBool.

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
JayK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Sa 25.06.05 18:19 
Und wie lasse ich das Verzeichnis erstellen?
Ich kann ja dem Benutzer nicht sagen: geh mal in den Ordner und mach da was, damit die Ini-Datei auch da landet und du das Prog zukriegst!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 25.06.05 18:23 
user profile iconJayK hat folgendes geschrieben:
Und wie lasse ich das Verzeichnis erstellen?
Ich kann ja dem Benutzer nicht sagen: geh mal in den Ordner und mach da was, damit die Ini-Datei auch da landet und du das Prog zukriegst!
Hat auch keiner behauptet. Such einfach mal im Forum, es ist recht unwahrscheinlich, dass Du der erste bist, der ein Verzeichnis erstellen will. :roll:

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Tobias1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Sa 25.06.05 18:24 

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
JayK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Sa 25.06.05 19:33 
@tobias: Danke ;)

Das mit dem Verzeichnis klappt dann soweit.
Aber wenn ich den hier mache:
ausblenden Delphi-Quelltext
1:
2:
Pref.RequestSave.Checked := ini.ReadBool('General', 'RequestSave',
                                         true);

Kommt eine Zugriffsverletzung bei Adresse 00000340. :roll:
JayK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Sa 25.06.05 20:00 
Es liegt schonmal am Pref.RequestSave.Checked.
Wenn ich es so mache kommt er über das Laden hinweg:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var tempB: Boolean;
begin
  ...
  tempB := ini.ReadBool('General', 'RequestSave', true);
  Pref.RequestSave.Checked := tempB  // <- hier Fehler
end;
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 25.06.05 20:10 
die Form Pref ist aber schon irgendwo erzeugt wurden?

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
JayK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Sa 25.06.05 20:24 
Hat sich erledigt.
Das Formular Pref war zu der Zeit noch gar nicht erstellt worden :autsch: