如题,我自己写了一小段程序,一编译就提示错误,好像是说“string”与“integer”类型不匹配~~
我就找了一个ORD转换一下~还是不行~~
请高手帮我写一段这个功能的代码啊!谢谢!最好把代码全部贴上来哦!呵呵!

解决方案 »

  1.   


    var
      i: Integer;
    begin
      Edit2.Text := '';
      for i := 1 to Length(Edit1.Text) do
      Edit2.Text := Edit2.Text + IntToStr(Ord(Edit1.Text[i]))+' ';
    end;
      

  2.   

    请问这句是什么意思啊?Length(Edit1.Text)
    这句是开始转换ASCII的语句吧?IntToStr(Ord(Edit1.Text[i])请问INTTOSTR是什么意思呢?
    谢谢,我还比较菜~请多指教~呵呵~
      

  3.   

    Length就是取字符串的长度
    每个字符对应一个ASCII码,IntToStr就是将整型数转换成字符串。
    只有转成字符串,才可以用 + 将所有的串连接起来。
      

  4.   


    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;