implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); var wFile:TextFile; wFileName,s,t:String; i:Integer;begin s:=Edit1.Text; t:=Edit2.Text; if Trim(Edit3.Text)='' then begin showmessage('输入函数名'); exit; end; if length(s)=0 then begin showmessage('输入提示字符串'); exit; end; if length(t)=0 then begin showmessage('请输入变量名'); exit; end; t:=Edit2.Text; wFileName:= 'ByTeCrypt.txt'; AssignFile(wFile, wFileName); Rewrite(wFile); Writeln(wfile,'/////////////// '+edit1.text+'Begin///////////////////////'); Writeln(wfile,'function '+edit3.text+':String;'); Writeln(wFile,'var'); Writeln(wFile,' '+t+':array[1..'+IntToStr(Length(s))+'] of char;'); //生成定义t:array[1..?] of char Writeln(wFile,'begin'); for i:=1 to Length(s) do begin Writeln(wFile, ' '+t+'['+IntToStr(i)+']:=Char('+IntToStr(Ord(s[i]))+');'); //生成语句t[?]:=Char(?); end; Writeln(wFile,' Result:='+t+';'); Writeln(wFile,'end;'); Writeln(wfile,'/////////////// '+edit1.text+'End///////////////////////'); CloseFile(wFile); Memo1.Lines.LoadFromFile('ByTeCrypt.txt'); showmessage('执行完毕,请查看同目录下ByTeCrypt.txt文件!');end;
var
i: Integer;
begin
Edit2.Text := '';
for i := 1 to Length(Edit1.Text) do
Edit2.Text := Edit2.Text + IntToStr(Ord(Edit1.Text[i]))+' ';
end;
这句是开始转换ASCII的语句吧?IntToStr(Ord(Edit1.Text[i])请问INTTOSTR是什么意思呢?
谢谢,我还比较菜~请多指教~呵呵~
每个字符对应一个ASCII码,IntToStr就是将整型数转换成字符串。
只有转成字符串,才可以用 + 将所有的串连接起来。
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
wFile:TextFile;
wFileName,s,t:String;
i:Integer;begin
s:=Edit1.Text;
t:=Edit2.Text;
if Trim(Edit3.Text)='' then
begin
showmessage('输入函数名');
exit;
end;
if length(s)=0 then
begin
showmessage('输入提示字符串');
exit;
end;
if length(t)=0 then
begin
showmessage('请输入变量名');
exit;
end;
t:=Edit2.Text;
wFileName:= 'ByTeCrypt.txt';
AssignFile(wFile, wFileName);
Rewrite(wFile);
Writeln(wfile,'/////////////// '+edit1.text+'Begin///////////////////////');
Writeln(wfile,'function '+edit3.text+':String;'); Writeln(wFile,'var');
Writeln(wFile,' '+t+':array[1..'+IntToStr(Length(s))+'] of char;'); //生成定义t:array[1..?] of char
Writeln(wFile,'begin');
for i:=1 to Length(s) do
begin
Writeln(wFile, ' '+t+'['+IntToStr(i)+']:=Char('+IntToStr(Ord(s[i]))+');'); //生成语句t[?]:=Char(?);
end;
Writeln(wFile,' Result:='+t+';');
Writeln(wFile,'end;');
Writeln(wfile,'/////////////// '+edit1.text+'End///////////////////////');
CloseFile(wFile);
Memo1.Lines.LoadFromFile('ByTeCrypt.txt');
showmessage('执行完毕,请查看同目录下ByTeCrypt.txt文件!');end;