Autor Beitrag
DelphiMarkus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: So 25.11.07 10:43 
Hallo!

Ich habe ein Problem mit INI-Dateien.
Ich kann meinen Fehler einfach nicht finden.

Das komische ist, wenn ich ins RichEdit etwas eingebe er mir die Fensterposition nicht speichen kann.

Hier ist der Quellcode:
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:
uses {..}, INIFiles;
{..}
var
ini : TIniFile;
Pfad : String;
{..}
procedure TForm1.FormCreate(Sender: TObject);
begin
  Pfad := Application.ExeName;
  Pfad := (Copy(Pfad, 1, Length(Pfad) -8));
  ini := TIniFile.Create(Pfad+'einstellungen.ini');
  try
    Groesse :=    ini.ReadInteger('Schriftart','Size',12);
    Form1.Left := ini.ReadInteger('Fenster','Left',0);
    Form1.Top :=  ini.ReadInteger('Fenster','Top',0);
  finally
    ini.Free;
  end;
end;
{..}
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  ini := TIniFile.Create(Pfad+'einstellungen.ini');
  try
    ini.WriteInteger('Fenster', 'Left', Form1.Left);
    ini.WriteInteger('Fenster', 'Top', Form1.Top);
    ini.WriteInteger('Schriftart', 'Size', Groesse);
    ini.Free;
  except
    Application.MessageBox('Fehler beim speichern der ini-Datei!', 'Fehler', 16)
  end;
  Application.Terminate;
end;


Ich fände es nett wenn mir jemand helfen würde.

Ervovm Wzmp!


Zuletzt bearbeitet von DelphiMarkus am So 25.11.07 11:19, insgesamt 1-mal bearbeitet
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: So 25.11.07 10:49 
Hi,

ausblenden Delphi-Quelltext
1:
2:
3:
ini.WriteInteger('Schriftart', 'Size', Groesse);
ini.UpdateFile;
ini.Free;


Xion

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: So 25.11.07 10:53 
Danke Xion, aber es hat nicht funktioniert!
Es kommt immernoch die Fehlermeldung.
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: So 25.11.07 10:54 
user profile iconDelphiMarkus hat folgendes geschrieben:
die Fehlermeldung.

welche lautet? (achso...wart mal kurz...)


mach mal das try weg und guck mal, was dann für ne fehlermeldung kommt

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: So 25.11.07 10:59 
Das hat eine Zugriffsverletzung gebracht und das Programm lässt sich nur per Taskmanager beenden.

Screenshot im Anhang.
Einloggen, um Attachments anzusehen!
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: So 25.11.07 11:03 
user profile iconDelphiMarkus hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
  Pfad := Application.ExeName;
  Pfad := (Copy(Pfad, 1, Length(Pfad) -8));



besser so:
ausblenden Delphi-Quelltext
1:
2:
  Pfad := Application.ExeName;
  Pfad := ExtractFilePath(Pfad);



hmm, in welcher Zeile kommt denn der Fehler? Beim Schreiben, oder beim Free?

//Edit: setze mal nach jedem Free noch ein Ini:=nil hin

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: So 25.11.07 11:10 
Der Fehler kommt ohne try bei:
ausblenden Delphi-Quelltext
1:
ini.WriteInteger('Fenster', 'Top', Form1.Top);					

da sagt er dann Zugriffsverletzung.

Mit try:
ist er an der selben Stelle, nur, dass er dann die Messagebox anzeigt.

// Edit: das mit dem ini:=ni hat auch nicht geklappt. Der Fehler kommt ja vorher.
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: So 25.11.07 11:14 
user profile iconDelphiMarkus hat folgendes geschrieben:
Edit: das mit dem ini:=ni hat auch nicht geklappt. Der Fehler kommt ja vorher.

auch oben beim laden ;)

user profile iconDelphiMarkus hat folgendes geschrieben:
Der Fehler kommt ohne try bei:
ausblenden Delphi-Quelltext
1:
ini.WriteInteger('Fenster', 'Top', Form1.Top);					

hmm, wenn Form1<>nil dann müsste das eigentlich gehen...

(und irgendwie lädst du die Schriftgröße von einer ganz andren Stelle als du sie speicherst ^^ )

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: So 25.11.07 11:19 
Hat auch nicht geholfen.
Der Fehler ist immernoch an der selben Stelle.
Zitat:
(und irgendwie lädst du die Schriftgröße von einer ganz andren Stelle als du sie speicherst ^^ )

Das war nicht extra, hat aber nichts mir dem Fehler zutun.
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: So 25.11.07 11:26 
hmm, also bei mir läuft der Code...selbst wenn ich die Datei schreibgeschützt mache, kommt keine AV...

ausblenden 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:
procedure TForm1.FormCreate(Sender: TObject);
begin
  Pfad := Application.ExeName;
  Pfad := ExtractFilePath(Pfad);
  ini := TIniFile.Create(Pfad+'einstellungen.ini');
  try
    Form1.Left := ini.ReadInteger('Fenster','Left',0);
    Form1.Top :=  ini.ReadInteger('Fenster','Top',0);
  finally
    ini.Free;
    ini:=nil;
  end;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  ini := TIniFile.Create(Pfad+'einstellungen.ini');
  try
    ini.WriteInteger('Fenster', 'Left', Form1.Left);
    ini.WriteInteger('Fenster', 'Top', Form1.Top);
    ini.WriteInteger('Fenster', 'Groesse', Groesse);
    ini.UpdateFile;
    ini.Free;
    ini:=nil;
  except
    Application.MessageBox('Fehler beim speichern der ini-Datei!', 'Fehler', 16)
  end;
  Application.Terminate;
end;

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: So 25.11.07 11:34 
Funktioniert bei mir einfach nicht.
(Pass bloß auf Delphi!! Ich zerfalle gleich!!!)

Ich schicke dir das Programm und den Code mal als PM.
Vielleicht findest du dann den Fehler!
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: So 25.11.07 11:48 
user profile iconXion hat folgendes geschrieben:

hmm, wenn Form1<>nil dann müsste das eigentlich gehen...

genau das ist das Problem...nur warum...

(Edit:
Application.Terminate; ist unsinn...und daran liegts auch, warum weiß ich nicht genau, aber das ist das Problem. Lass es einfach weg)

Edit2: ne, daran liegts doch nicht...nochmal gucken

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
Popov
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1655
Erhaltene Danke: 13

WinXP Prof.
Bei Kleinigkeiten D3Pro, bei größeren Sachen D6Pro oder D7
BeitragVerfasst: So 25.11.07 11:52 
Versuche es mal mit meiner EasyIniAppExe Unit hier: www.delphi-forum.de/....php?p=127274#127274 Kopiere den Quelltext in einen Texteditor und speichere ihn unter EasyIniAppExe.pas ab. Am besten gleich in deinen Projektordner. Damit ist das Ganze etwas einfacher.

Ich hab mit dem Code hier und der EasyIniAppExe Unit keine Probleme. Das Fenster wird beim nächsten Start an alten Stelle geöffnet.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
uses
  EasyIniAppExe;

procedure TForm1.FormCreate(Sender: TObject);
var
  Groesse: Word;
begin
  Groesse :=    ReadIniInteger('Schriftart','Size',12);
  Form1.Left := ReadIniInteger('Fenster','Left',0);
  Form1.Top :=  ReadIniInteger('Fenster','Top',0);
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
  Groesse: Word;
begin
  WriteIniInteger('Fenster', 'Left', Form1.Left);
  WriteIniInteger('Fenster', 'Top', Form1.Top);
  WriteIniInteger('Schriftart', 'Size', Groesse);
end;

_________________
Popov
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: So 25.11.07 11:54 
Geht immernoch nicht!
Das war wirklich Blodsinn, aber es funktioniert noch nicht.
Es kommt immer dann wenn ich etwas ins RichEdit eingebe und dann auf umwandeln klicke.

Wenn das so weitergeht dann lass ich es raus.

// Edit: Das Problem kommt nur dann wenn etwas in RichEdit1 steht!
// Edit: Auch wenn ich in CloseQuery die Felder leere gibt es einen Fehler
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: So 25.11.07 12:09 
hab jetzt mal die Verschlüsselungsroutine geändert, jetzt läufts prima...ist mir irgendwie unerklärlich warum deßwegen die Form=nil ist...

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
DelphiMarkus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 303

OpenSuSE
Delphi 2009 Pro., Lazarus
BeitragVerfasst: So 25.11.07 12:25 
Danke!!

Aber ich kann es mit Delphi 7 PE nicht öffnen. Er bleibt hängen!
Du hast es wahrscheinlich mit D2005 gemacht, ist jetzt etwas Arbeit für mich aber es lohnt sich.
Ich werde jetzt mir Nodepad++ rauskopieren und in meinen Code , den Delphi 7 öffen kann einfügen.

Vielen Dank!

Jetzt macht das übersetzten noch mehr Spaß!

Bin fertig!
Jetzt funktioniert es wunderbar.
Zorro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 76

Win 2000, Win XP Pro
Delphi 7 Architect
BeitragVerfasst: Sa 08.12.07 01:23 
user profile iconDelphiMarkus hat folgendes geschrieben:
Der Fehler kommt ohne try bei:
ausblenden Delphi-Quelltext
1:
ini.WriteInteger('Fenster', 'Top', Form1.Top);					

da sagt er dann Zugriffsverletzung.

Mit try:
ist er an der selben Stelle, nur, dass er dann die Messagebox anzeigt.

// Edit: das mit dem ini:=ni hat auch nicht geklappt. Der Fehler kommt ja vorher.


Lass das "Form1." weg, du bist ja ohnehin in einer Methode des Formulars. Damit vermeidest du den Fehler, wenn dein Formular nicht in der Variablen Form1 steckt, sondern in einer anderen (zB weil per Code erzeugt).

Greetz
Zorro