Autor Beitrag
Faithless
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 17.11.05 15:04 
Hi Jungs und Mädels!

Ich bins schon wieder, hab folgendes problem, ich machen in meinem programm eine If abfrage am anfangn, die sieht so aus!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Begin
 IF FileExists('c:\Windows\System32\web.txt')= False
 Then FileCreate('c:\Windows\System32\web.txt')
 Else memoWeb.Lines.LoadFromFile ('c:\Windows\System32\web.txt');
End;


Das funktioniet soweit auch problem los, aber ein fehler taucht wieder dann auf, wenn die datein nicht existiereten er sie erstellt hat und ich dann onClose wieder was in die Files schreiben will! Dann crasht er. "Datei blablubber kann nicht geschreiben werden" ! Also hab ichs dann mit der FileClose funktion versucht! Aber irgendwie geht das auch net so recht! Hier ist auch der code dazu! wenn mir jemand helfen könnte fänd ichs sehr gut! Danke schon mal im vorraus!


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

begin
 FileClose(FileCreate('c:\Windows\System32\web.txt'));
 FileClose(FileCreate('c:\Windows\System32\chat.txt'));
 FileClose(FileCreate('c:\Windows\System32\sonstige.txt'));
 memoWeb.Lines.SaveToFile('c:\Windows\System32\web.txt');
 memoChat.Lines.SaveToFile('C:\Windows\System32\chat.txt');
 memoSonstige.Lines.SaveToFile('C:\Windows\System32\sonstige.txt');
 end;
End.


Mfg

Faithless
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Do 17.11.05 15:12 
Also die drei FileClose-Zeilen kannst du dir sparen, die sind so genau sinnlos.

SaveToFile kann auch damit umgehen, wenn die Datei noch nicht da ist, es erstellt sie dann einfach.

Wo genau knallts denn? Hast du Schreibrechte in dem Verzeichnis?

_________________
Bravery calls my name in the sound of the wind in the night...
Faithless Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 17.11.05 15:31 
Naja Genau genommen muss das programm die datein aber sehr wohl am anfang erstellen wenns gestrate wird, weil es sollen ja aus den datein die texte der memoboxen geladen werden, und das ganz am anfang! Und wenn die datein net da sind kann er logischerweise nix laden, also lass ich sie ihn in der formcreate erstellen! Ist quasie ne routine für einen user der das programm das erste mal auf seinem rechner startet.


Naja es crashed dann wenn die datein nicht vorhandne waren das prog sie erstellt hat, und ich dann wenn das programm geschlossen wird was in die files schreiben will! Dann knallts
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Do 17.11.05 15:37 
In welcher Zeile knallts denn? Und wie? Zugriffsverletung oder was anderes?

_________________
Bravery calls my name in the sound of the wind in the night...
Faithless Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 17.11.05 15:42 
kann ich dir net sagen! der kompiler kompiliert es das passiert dann erst wenn cih das programm benutze, und komischer weise auch net wenn cihs in delphi ausfüre nur wenn ichs dannn als exe benutz
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Do 17.11.05 15:50 
Und welche Fehlermeldung kommt da?

_________________
Bravery calls my name in the sound of the wind in the night...
Faithless Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 17.11.05 16:03 
Datei kann nicht geschreiben werden !
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Do 17.11.05 16:08 
Hast du die Schreibrechte kontrolliert? Hat vielleicht ein anderer Prozess die Datei noch offen?

_________________
Bravery calls my name in the sound of the wind in the night...
Faithless Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 17.11.05 16:38 
nein ausser meinem programm ist nicht offen, ich hab auf dem laufwerk administrator rechte und somit auch vollzugriff
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Do 17.11.05 16:42 
Mh, dann poste am besten mal den ganzen Quelltext..

_________________
Bravery calls my name in the sound of the wind in the night...
Faithless Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 17.11.05 16:45 
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:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
unit PWManager;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, Buttons;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    btnLogin: TButton;
    gpxPW: TGroupBox;
    MemoWeb: TMemo;
    memoChat: TMemo;
    memoSonstige: TMemo;
    WebAdd: TStringGrid;
    ChatAdd: TStringGrid;
    SonstigeAdd: TStringGrid;
    lblWeb: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    btnAdd: TButton;
    btnAdd1: TButton;
    btnAdd2: TButton;
    btnclose: TBitBtn;
    ListeWeb: TButton;
    ListeSonstige: TButton;
    ListeChat: TButton;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure btnLoginClick(Sender: TObject);
    procedure btnAddClick(Sender: TObject);
    procedure btnAdd1Click(Sender: TObject);
    procedure btnAdd2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation



{$R *.dfm}



procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Caption:='Schatzis Passwordmanager';

btnclose.Kind:=bkClose;
memoweb.Clear;
memochat.Clear;
memoSonstige.Clear;
Begin
 IF FileExists('c:\Windows\System32\web.txt')= False
 Then FileCreate('c:\Windows\System32\web.txt')
 Else memoWeb.Lines.LoadFromFile ('c:\Windows\System32\web.txt');
End;

Begin
 IF FileExists('c:\Windows\System32\chat.txt')= False
 Then FileCreate('c:\Windows\System32\chat.txt')
 Else memoChat.Lines.LoadFromFile ('c:\Windows\System32\chat.txt');
End;
Begin
 IF FileExists('c:\Windows\System32\sonstige.txt')= False
 Then FileCreate('c:\Windows\System32\sonstige.txt')
 Else memoSonstige.Lines.LoadFromFile('c:\Windows\System32\sonstige.txt');
End;
gpxPw.Visible:=False;
Edit1.Clear;
Edit1.PasswordChar:='-';
btnLogin.Caption:='Login';
gpxPW.Caption:='Passwörter';
WebAdd.Cells[0,0]:='Website';
WebAdd.Cells[1,0]:='User';
WebAdd.Cells[2,0]:='Passwort';

ChatAdd.Cells[0,0]:='Website';
ChatAdd.Cells[1,0]:='User';
ChatAdd.Cells[2,0]:='Passwort';

SonstigeAdd.Cells[0,0]:='Website';
SonstigeAdd.Cells[1,0]:='User';
SonstigeAdd.Cells[2,0]:='Passwort';

BtnAdd.Caption:='Add';
BtnAdd1.Caption:='Add';
BtnAdd2.Caption:='Add';

end;

procedure TForm1.btnLoginClick(Sender: TObject);
begin
    Begin
     If Edit1.Text = 'Haus' then gpxPW.Visible := True
     Else (MessageDlg ('Flasches Passwort', mtError, [mbOK],0));
    End;

end;

procedure TForm1.btnAddClick(Sender: TObject);
begin
 MemoWeb.Lines.Add('')  ;
 MemoWeb.Lines.Add('Website:' +#9 +WebAdd.Cells[0,1]);
 MemoWeb.Lines.Add('User:' +#9 + WebAdd.Cells[1,1]);
 MemoWeb.Lines.Add('Pass:' +#9 +WebAdd.Cells[2,1]);
 MemoWeb.Lines.Add('_______________');
 end;

procedure TForm1.btnAdd1Click(Sender: TObject);
begin
 MemoChat.Lines.Add('')  ;
 MemoChat.Lines.Add('Website:' +#9 +ChatAdd.Cells[0,1]);
 MemoChat.Lines.Add('User:' +#9 + ChatAdd.Cells[1,1]);
 MemoChat.Lines.Add('Pass:' + #9 +ChatAdd.Cells[2,1]);
 MemoChat.Lines.Add('_______________');
end;

procedure TForm1.btnAdd2Click(Sender: TObject);
begin
 MemoSonstige.Lines.Add('')  ;
 MemoSonstige.Lines.Add('Website:' +#9 +SonstigeAdd.Cells[0,1]);
 MemoSonstige.Lines.Add('User:' +#9 + SonstigeAdd.Cells[1,1]);
 MemoSonstige.Lines.Add('Pass:' + #9 +SonstigeAdd.Cells[2,1]);
 MemoSonstige.Lines.Add('_______________');

 end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

begin
 FileClose(FileCreate('c:\Windows\System32\web.txt'));
 FileClose(FileCreate('c:\Windows\System32\chat.txt'));
 FileClose(FileCreate('c:\Windows\System32\sonstige.txt'));
 memoWeb.Lines.SaveToFile('c:\Windows\System32\web.txt');
 memoChat.Lines.SaveToFile('C:\Windows\System32\chat.txt');
 memoSonstige.Lines.SaveToFile('C:\Windows\System32\sonstige.txt');
 end;

End.
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Do 17.11.05 16:51 
So wie ich das sehe, kannst dur dir den ganzen FileCreate und FIleClose - Kram sparen.

Schreib mal ins FormCreate and der entsprechenden Stelle

ausblenden Delphi-Quelltext
1:
2:
3:
4:
Begin  
 If FileExists('c:\Windows\System32\web.txt') then
    memoWeb.Lines.LoadFromFile ('c:\Windows\System32\web.txt');  
End;


Das selbe mit den andren Files.

Aus dem FormClose wirfst du den FileClose- Krempel weg. Sollte gehen.

Beim Start schaut er nach, ob die Datei da is, wenn ja, liest er daruas ins memo ( wenn nicht, tut er nix ). Beim schließen wird der Inhalt des Memos in die Datei gespeichert. Existiert sie noch nciht, wird die angelegt.

_________________
Bravery calls my name in the sound of the wind in the night...
Faithless Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 17.11.05 17:05 
Ok danke! klappt so
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 17.11.05 17:26 
Aber bei mir nicht. Und das kann ich dir sagen ohne es probiert zu haben. Mein Windowsverzeichnis heißt "WinNT" und außerdem hab eich dort keine Schreibrechte. Aber auch wenn es funktionieren würde, würde ich dich erschlagen, weil du ungefragt mein Systemverzeichnis zu müllst. Solche Daten gehören ins %HOMEDIR% des Anwneders. Warum kannst du hier nachlesen: www.luckie-online.de...rtikel/HOMEDIR.shtml
Faithless Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 17.11.05 18:34 
Danke sehr informatiev dien artikel!