Autor Beitrag
Flinthrc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: So 21.05.06 18:34 
Hallo!

Ich verschlüssele mit dieser Verschlüsselungsmethode meine Strings.

Diese möchte ich nun in einer Datei speichern und zu gegebener Zeit wieder auslesen lassen.

Mit einer Textdatei funktioniert das Speichern auch gut, aber wenn ich die Strings dann wieder auslesen lasse werden die Strings nicht korrekt entschlüsselt.

Wie muss ich die Strings speichern, damit sie später wieder entschlüsselt werden können?
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: So 21.05.06 18:37 
Zeig mal wie du in einer Textdatei speicherst und wieder ausliest.
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: So 21.05.06 18:42 
Speichern:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var t:textfile;
begin
{...}
i:=1;
AssignFile(t, 'fragen.qm1000');
Rewrite(t);
while i <= 9 do
begin
{...}
Writeln(t,fragen[i]);
i:=i+1;
end;

closeFile(t);


und laden:

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 Fragenlesen;
var datei:textfile;
    i:integer;
begin
  dateiname:='fragen.qm1000';
  if fileexists(dateiname) then
   begin
    assignfile(datei,dateiname);
    reset(datei);
    i:=0;
    anz_fragen:=0;
    setlength(fragen,100);
    while not (eof(datei)) do
    begin
      readln(datei,fragen[i]);
      fragen[i]:=Decrypt(Fragen[i],9,3,39,99);
      i:=i+1;
      anz_fragen:=anz_fragen+1;
    end;
    closefile(datei);
    setlength(fragen,i);
    anz_fragen:=anz_fragen-1;
   end
  else
   begin
   Showmessage('Fragen konnten NICHT geladen werden!');
   end;

end;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Green
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 21.05.06 18:43 
ohje warum so kompliziert, mach das doch mit SaveToFile(Path); ;)
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: So 21.05.06 18:44 
Wie soll das aussehen?
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: So 21.05.06 18:46 
Ist "fragen" in dynamisches Array? Wieso kommt da ein setlength(fragen,i); zum Schluss?

Edit: OK, hab das SetLength(fragen,100) oben übersehen.

Nimm einfach eine TStringList. Mit TStringList.Add kannst du die Fragen der Liste hinzufügen, danach mit TStringlist.SaveToFile(Dateiname) abspeichern. Mit TStringList.LoadFromFile in den Speicher laden.
Green
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 21.05.06 18:48 
Genau das meinte ich...
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: So 21.05.06 18:49 
fragen: array of string;

Um das Array zu verkleinern.
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: So 21.05.06 18:55 
Wenn ich

TStringList.Add:='blablalba';

verwende, kommt ein Fehler:

"Nicht genügend wirkliche Parameter."
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 21.05.06 18:59 
user profile iconFlinthrc hat folgendes geschrieben:
Wenn ich

TStringList.Add:='blablalba';

verwende, kommt ein Fehler:

"Nicht genügend wirkliche Parameter."

Du mußt die Methode auch auf ein Objekt anwenden, nicht auf die klasse:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var
  List: TSringList;
  ...
begin
    ...
    List := StrinList.Create;
    ...
    List.Add:='blablalba';

_________________
Markus Kinzler.
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: So 21.05.06 19:07 
Bei

List := StringList.Create;

kommt bei mir "Nicht deklarierter Bezeichner".
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: So 21.05.06 19:11 
List := TStringList.Create; :roll:
Flinthrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: So 21.05.06 19:13 
Das hab ich auch schon probiert.

Da kommt dann bei

List.Add:='Wie....';

"Nicht genügend wirkliche Parameter."
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: So 21.05.06 19:13 
List.Add('Das ist ein String'); :roll:
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 21.05.06 19:15 
List.Add('DeinString');

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)