I am making simple encrypt/decrypt program in Lazarus with 2 buttons, one for encrypt and one for decrypt. I also have two memo boxes (or just two memos ). I tested my algorithm and it works but when i tried implementing it in user friendly app i got this problem.
I have this function:
function enc(x:string):string;
var
y:string;
p,q:integer;
m:char;
begin
y:=x[1];
for p:=2 to Length(x)do
begin
q:=p-1;
if chr(ord(x[p]))=' ' then
m:='!'
else if ord(x[p])>ord(x[q]) then
m:=Succ(chr(ord(x[p])))
else
m:=Pred(chr(ord(x[p])));
Y:=y+m ;
end;
enc:=y;
end;
and one procedure to call this function
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text:=enc(Memo2.Text);
end;
I compiled program and it worked but when i tried to enter some text and encrypt that text i got this error
exception class 'External: SIGSEGV'
In file 'unit1.pas' at line 46: y:=x[1];
I recently started to learn pascal and to use lazarus soo sry if this Q is stupid but i really want to know what I'm doing wrong.