Autor Beitrag
Lux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Do 16.12.04 09:59 
Hallo Leute.
Nach langer Pause fange ich wieder an Delphi zu programmieren, und hab nun auch schon 1 Problem.

Und zwar möchte ich mit einem Programm eine Datei öffnen, und diesen Pfad der Datei dann in eine INI-Datei speichern.

Das Problem was ich nun habe ist folgendes:
Beim Schließen der Datei (Form1.FormDestroy) speichert er die INI-Datei in den Pfad, der vorher mit OpenDialog1 geöffnet wurde.

Heißt wenn ich mit meinem OpenDialog1 eine Datei lade z.B. C:\temp\List.txt und will dann die Ini-Datei speichern dann speichert er sie mir auch in den Pfad C:\temp\List.txt und nicht in den Pfad, wo das Programm ausgeführt wird.
Könnt ihr mir dabei helfen?

Hier der Quellcode:

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.Oeffnen1Click(Sender: TObject);
begin
  if OpenDialog1.execute then
    pfadderliste := OpenDialog1.FileName;  //Pfad der List in eine globale Variable laden
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
  IniDat: TIniFile;
begin
  IniDat := TIniFile.Create('.\Cogpack.ini');
  with IniDat do
  begin
    WriteString('Pfade','Liste',pfadderliste);
  end;
  IniDat.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  IniDat : TIniFile;
begin
  IniDat := TIniFile.Create('.\Cogpack.ini');
  with IniDat do
  begin
    pfadderliste := ReadString('Pfade','Liste','C:\temp\List.txt');
  end;
  IniDat.Free;
end;

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Do 16.12.04 10:06 
Lux hat folgendes geschrieben:
Heißt wenn ich mit meinem OpenDialog1 eine Datei lade z.B. C:\temp\List.txt und will dann die Ini-Datei speichern dann speichert er sie mir auch in den Pfad C:\temp\List.txt und nicht in den Pfad, wo das Programm ausgeführt wird.

Das ist auch richtig. Weil sich das Current Directory dadurch verändert hat.

ausblenden Delphi-Quelltext
1:
IniDat := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Cogpack.ini');					


So sollte es funktionieren.

_________________
Ciao, Sprint.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Do 16.12.04 10:10 
Hey Super!!!!

Vielen dank! Da wäre ich nie drauf gekommen (Erstmal nachlesen muss was ExtractfilePath und ParamStr sind :lol: :wink: )

Danke nochmal. Das brgint mich ein Stück weiter beim Proggen ;)

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.