Autor Beitrag
sPeeD2k5
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72



BeitragVerfasst: Fr 26.01.07 08:56 
Hi jungs zunächst erstma mein code:


Gui:
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:
unit Gui;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    GroupBox2: TGroupBox;
    Label3: TLabel;
    EdSchluessel: TEdit;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    EdFile: TEdit;
    Label4: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);


  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  MyKryptool: TKryptool;

implementation

{$R *.dfm}




procedure TForm1.FormCreate(Sender: TObject);
begin
  //Form1 := TForm1.create(nil);
  MyKryptool := TKryptool.create;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
  MyKryptool.SetzeKlartext(Memo1.Text);
  MyKryptool.SetzeSchluessel(EdSchluessel.Text[1]);
  if RadioButton1.checked = true then
    if RadioButton4.checked = true then
      MyKryptool.Verschluesseln('1',TRUE);
end;




end.


TKryptomatik:

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:
unit TKryptomatik;

interface

//--------------------  ggf Uses-Liste einfügen !  --------------------
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TKryptool = class
    Memo1: TMemo;
    Memo2: TMemo;
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    GroupBox2: TGroupBox;
    Label3: TLabel;
    EdSchluessel: TEdit;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    EdFile: TEdit;
    Label4: TLabel;

  private //Attribute
    Geheimtext : String;
    Klartext : String;
    Schluessel : String;

  private //Methoden
    procedure Caesar (Text: String; Schluessel: String);

  public //Methoden
    procedure SetzeGeheimtext (pGeheimtext: String); virtual;
    procedure SetzeKlartext (pKlartext: String); virtual;
    procedure SetzeSchluessel (pSchluessel: String); virtual;
    procedure Verschluesseln (Modus: Char; Verschl: Boolean); virtual;
    function GibGeheimtext : String;
    function GibKlartext : String;
    function GibSchluessel : String;
    constructor create;
   end;

implementation

//+---------------------------------------------------------------------
//|         TKryptool: Methodendefinition
//+---------------------------------------------------------------------

//-----------------Konstruktor der Fachklasse---------------------------

constructor TKryptool.create;
begin
  inherited create;
  Geheimtext:='';
  Klartext:='';
  Schluessel:='';
end;

//-------- Caesar (private) --------------------------------------------
procedure TKryptool.Caesar (Text: String; Schluessel: String);
var
i,abstand,wert,wert2 : Integer;
wert3 : char;

begin

    Abstand:=Ord(schluessel[1])-65; //abstand ausrechnen
    for i := 1 to Length(Text) do
      begin
        uppercase(Text[i]);
        wert:=Ord(Text[i]); //ASCII Wert von Text[i]
          if wert <> 32 then //solang kein Leerzeichen tue..
            begin
              wert2:=wert + Abstand; //verschlüsselter Wert
                if wert2 > 90 then
                  begin
                    wert2:=wert2 - 26;
                    wert3:=chr(wert2); //verschlüsseltes Zeichen
                    SetzeGeheimtext(wert3);
                  end
                else
                  wert3:=chr(wert2);  //verschlüsseltes Zeichen
                  SetzeGeheimtext(wert3);
            end;

      end;

end;

//-------- SetzeGeheimtext (public) ------------------------------------
procedure TKryptool.SetzeGeheimtext (pGeheimtext: String);

begin
  Geheimtext:='';
  Geheimtext:=Geheimtext + pGeheimtext;
end;

//-------- SetzeKlartext (public) --------------------------------------
procedure TKryptool.SetzeKlartext (pKlartext: String);
begin
  Klartext:='';
  Klartext:=Klartext + pKlartext;
end;

//-------- SetzeSchluessel (public) ------------------------------------
procedure TKryptool.SetzeSchluessel (pSchluessel: String);
begin
  Schluessel:='';
  Schluessel:=pSchluessel;
end;

//-------- Verschluesseln (public) -------------------------------------
procedure TKryptool.Verschluesseln (Modus: Char; Verschl: Boolean);
begin
  if Modus = '1' then
    if Verschl = True then
      Caesar(GibKlartext,GibSchluessel);

end;

//-------- GibGeheimtext (public) --------------------------------------
function TKryptool.GibGeheimtext : String;
begin
  Memo2.Text:=Geheimtext;
end;

//-------- GibKlartext (public) ----------------------------------------
function TKryptool.GibKlartext : String;
begin
  Memo1.Text:=Klartext;
end;

//-------- GibSchluessel (public) --------------------------------------
function TKryptool.GibSchluessel : String;
begin
  EdSchluessel.Text:=Schluessel;
end;

end.


mein problem liegt bei Tkryptomatik und zwar folgend Zeile:

Abstand:=Ord(schluessel[1])-65; //abstand ausrechnen

Ich bekomm laufend eine Fehlermeldung von wegen Zugriffsverletzung.. hat jemand ne idee worans liegen könnte?
Logikmensch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 390

Win XP
Delphi 2007 Prof., XE2, XE5
BeitragVerfasst: Fr 26.01.07 09:56 
Kann eigentlich nur sein, dass Schluessel beim Erreichen der betreffenden Zeile immernoch Null-Länge hat. Du greift mit Schluessel[1] auf ein Element zu, ohne zu prüfen, ob der String überhaupt diese Länge von >=1 hat. Sollte man sich aber angewöhnen, sieht auch der Compiler nicht gerne sowas (wenn Du Delphi 2005 oder 2006 hast, sollte er Dich sogar warnen.

ich hoffe, dass Dein Code von deiner TKryptomatic nicht vollständig gepostet wurde? Es fehlen nämlich sämtliche Initialisierungen der ganzen Memos und Edit-Objekte darin.

Moderiert von user profile iconUGrohne: Zeitnahe Beiträge zusammengefasst.

_________________
Es gibt keine Probleme - nur Lösungen!