Autor Beitrag
Dandrolvorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Fr 06.05.05 12:14 
Ich möchte einen String mit XOR verschlüsseln, den verschlüsselten String dann einer Stringlist hinzufügen, und diese StringList dann in eine Textdatei speichern ...

Doch irgendwie bekomme ich eine Accesviolation:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
profile.Add(serverbox.Items[serverbox.ItemIndex]);
    profile.Add(e_nick.Text);

    temp := e_pw.Text;

       For i := 0 to length(temp) do
        temp[i] := char(byte(temp[i]) xor 12);

    profile.Add(temp);
    profile.SaveToFile('profiles.txt');


Danke schonmal

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 06.05.05 12:17 
hast du die stringlist anstädig erstellt und gibts sie auch wieder frei ?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
profile:= tStringlist.create;
  try
    profile.Add(serverbox.Items[serverbox.ItemIndex]);  
    profile.Add(e_nick.Text);  
    temp := e_pw.Text;   
    For i := 1 to length(temp) do  
      temp[i] := char(byte(temp[i]) xor 12);   
    profile.Add(temp);  
    profile.SaveToFile('profiles.txt'); 
  finally
    profile.free;
  end;


Zuletzt bearbeitet von F34r0fTh3D4rk am Fr 06.05.05 12:24, insgesamt 1-mal bearbeitet
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Fr 06.05.05 12:20 
Wie lautet der nullte Buchstaben des Worts "Hallo"? ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
profile:= tStringlist.create;   
  try   
    profile.Add(serverbox.Items[serverbox.ItemIndex]);     
    profile.Add(e_nick.Text);     
    temp := e_pw.Text;      
    For i := 0 to length(temp) do     
      temp[i] := char(byte(temp[i]) xor 12);      
    profile.Add(temp);     
    profile.SaveToFile('profiles.txt');    
  finally   
    profile.free;   
  end;
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 06.05.05 12:21 
Der Fehler gibt aber keine Acces Violation, da kommt dann zB auf Element 0 kann nicht zugegriffen werden :?
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Fr 06.05.05 12:30 
Nicht wenns in ner For-Schleife steht.

Habs gerade mal getestet und bekomme komischerweise auch keine Exception.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button2Click(Sender: TObject);
var s : string;
    i : integer;
begin
s := 'Hallo';
 for i := 0 to 4 do
   Memo1.lines.add(s[i]);
end;


Funktioniert sogar, obwohl eindeutig auf den 0-ten Buchstaben zugegriffen wird :gruebel:
Komisch.
Dandrolvorn Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Fr 06.05.05 12:41 
jo, 0 von Hallo ^^

jetzt gehts, danke
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Fr 06.05.05 12:41 
Ihr wisst aber schon um die CompilerMagic hinter Pascal-Strings und auch, daß der Zugriff von string[0] das letzte Byte des Pointers (oder des Reference Counter, ich weiß die Reihenfolge nicht mehr) zurückgibt? Der Zugirff selbst ist durchaus erlaubt, Delphi meckert nur, wenn er einen solchen Zugriff zur Compile-Zeit schon feststellen kann, weil für gewöhnlich ein Zugriff auf string[0] nichts ist, was ein gewöhnlicher Anwendungsprogrammierer jemals tun wollen könnte.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 06.05.05 12:45 
jo ich hatte es im oncreate, deshalb :P