Autor Beitrag
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Mo 05.05.08 09:30 
Gute Morgen EE,

ich hab heute mal versucht, nach dem Beispiel von Delphi-Treff.de, eine .ini Datei zu erzeugen und diese anschließend wieder auszulesen.

Hier mein Ansatz :
(in den uses hab ich IniFiles eingebunden)
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:
procedure TForm1.FormCreate(Sender: TObject);
var
ini: TIniFile;
begin
  ini:=TiniFile.Create('einstellungen.ini');
  ini.WriteString('Benutzer','Name','Test Person');
  ini.WriteString('Test1','Test2','Test3');
  ini.WriteInteger('Form1Size','Left','500');
  ini.WriteInteger('Form1Size','Top','500');
  ini.Free ;
end;

procedure TForm1.FormShow(Sender: TObject);
var
ini : TIniFile;
begin
  ini:=TIniFile.Create('einstellungen.ini');
  try
    Form1.Left:=ini.ReadInteger('Form1Size','Left','0');
    Form1.Top:=ini.ReadInteger('FormSize','Top','0');
  finally
  ini.Free ;
  end;
end;

end.


Nun bekomme ich in der highligt Zeile die Meldung
[Fehler] Unit1.pas(33): E2010 Inkompatible Typen: 'Integer' und 'string'

verstehe aber nicht warum ich hab extra drauf geachtet WriteInteger zu nutzten ?!


LG

GericasS

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mo 05.05.08 09:32 
Du musst den Wert dann auch als Integer übergeben:

ausblenden Delphi-Quelltext
1:
  ini.WriteInteger('Form1Size','Left',500);					
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Mo 05.05.08 09:37 
user profile iconXentar hat folgendes geschrieben:
Du musst den Wert dann auch als Integer übergeben:

ausblenden Delphi-Quelltext
1:
  ini.WriteInteger('Form1Size','Left',500);					


Ahh okay da lag der Fehler vielen Dank für die schnelle Hilfe =)

LG

GericasS

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 05.05.08 10:50 
user profile iconGericasS hat folgendes geschrieben:
Gute Morgen EE,

ich hab heute mal versucht, nach dem Beispiel von Delphi-Treff.de, eine .ini Datei zu erzeugen und diese anschließend wieder auszulesen.

Hier mein Ansatz :
(in den uses hab ich IniFiles eingebunden)
ausblenden Delphi-Quelltext
1:
  ini:=TiniFile.Create('einstellungen.ini');					


Zu einem Dateinamen gehört auch immer ein Pfad, um sie eindeutig identifizieren zu können. Ansonsten ist es reine Glücksache, ob die Datei gefunden wird oder nicht bzw. wo sie überhaupt erstellt wird.
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Mo 05.05.08 10:59 
user profile iconLuckie hat folgendes geschrieben:
Zu einem Dateinamen gehört auch immer ein Pfad, um sie eindeutig identifizieren zu können. Ansonsten ist es reine Glücksache, ob die Datei gefunden wird oder nicht bzw. wo sie überhaupt erstellt wird.


Hey Luckie,

hatte ich zu diesem Zeitpunkt noch nicht eingetragen, jetzt schon ! Trotzdem danke =)

Moderiert von user profile iconNarses: Zitat gekürzt

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
lblbw
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 122

Win XP, Win 7
Delphi7 Enterprise
BeitragVerfasst: Mo 05.05.08 14:18 
Hallo,

da ich ungefähr das gleiche Problem habe, brauch ich nicht ein extra Thread aufmachen. Das Abspeichern der Fensterposition klappt super. Leider wird beim starten die Fensterposition aber nicht übernommen:

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:
procedure TForm1.FormCreate(Sender: TObject);
var
  stream: TFilestream;
  version: TStringList;
//  Optionen: TStringList;
  t: String;
  s: String;
//  u: String;
begin
// ...
  ini:=TIniFile.Create(ExtractFilePath(ParamStr(0))+
    'config.ini');
  try
    form1.left:=ini.ReadInteger('Position','Links',0);
    form1.top:=ini.ReadInteger('Position','Oben',0);
  finally
    ini.free;
  end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ini:=TIniFile.create(ExtractFilePath(ParamStr(0))+
    'config.ini');
  ini.WriteInteger('Position','Links',Form1.Left);
  ini.WriteInteger('Position','Oben',Form1.Top);
  ini.Free;
end;
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Mo 05.05.08 14:27 
Musst du nicht das was in der .ini steht ins Form1.Create schreiben ?

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
lblbw
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 122

Win XP, Win 7
Delphi7 Enterprise
BeitragVerfasst: Mo 05.05.08 14:31 
So wollte ich das ja nicht machen. Er soll ja die Fensterposition speichern, und das kann man nunmal am besten im Close machen.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 05.05.08 14:33 
Pack den Code mal ins OnShow-Ereignis des Formulares.
lblbw
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 122

Win XP, Win 7
Delphi7 Enterprise
BeitragVerfasst: Mo 05.05.08 14:35 
Hab ich schon probiert. Die Anwendung wird immer in der Bildschirmmitte gestartet.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mo 05.05.08 14:36 
Du hast nicht zufällig Form1.Position = poScreenCenter gesetzt?
lblbw
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 122

Win XP, Win 7
Delphi7 Enterprise
BeitragVerfasst: Mo 05.05.08 14:40 
Hubs, das kommt davon, wenn man nicht genau nachschaut. Gut funktioniert. Aber ich sende noch nicht! Wg. gestern exe kann nicht erstellt werden :D :rofl: