这是用JSP编写的程序,好象有点类似于C语言,我看不懂,我想用DELPHI把这两个函数写出来,请高手帮忙,谢谢了!
<SCRIPT LANGUAGE="JavaScript">
<!--
function escapeStr(src) {
    var ret = "";
    for (i = src.length - 1; i >= 0; i--) {
        var ch = src.charCodeAt(i);
        if (ch == 10) {
            ch = 15;
        } else if (ch == 13) {
            ch = 16;
        } else if (ch == 32) {
            ch = 17;
        } else if (ch == 9) {
            ch = 18;
        } else {
            ch = ch + 5;
        }
        ret += String.fromCharCode(ch);
    }
    return ret;
}
function loginTrim() {
        var objLogin = document.all("p_login").value;
        var objPassword = document.all("p_password").value;
        var objCmpy = document.all("cmpyCode").value;
        document.all("cmpyCode").value = escapeStr(objCmpy);
       document.all("login").value = escapeStr(objLogin);
       document.all("password").value = escapeStr(objPassword);
    }
//-->
</SCRIPT>

解决方案 »

  1.   

    JSP是嵌入网页的程序,第一个函数没问题,第二个,从网页内部取网页的内容,delphi是做不到的
    function escapeStr(src:string) :string;
    var
      i:integer;
      ret:string;
      ch:byte;
    begin
        i := length(src) ;
        ret :='';
        while  i > 0 do
        begin
         dec(i);
         ch := byte(src[i]);
            if (ch = 10) then
                ch := 15
             else if (ch = 13) then
                ch := 16
             else if (ch = 32) then
                ch := 17
             else if (ch = 9) then
                ch := 18
             else
                ch := ch + 5;
            ret := ret+char(ch);
        end;
        result:= ret;
    end;
      

  2.   

    请问keiy(),提示这样的错误是怎么回事呢
    Unsatisfied forward or external declaration: 'TFormMain.escapeStr'
      

  3.   

    直接将function escapeStr(src:string) :string;写在implementation中就可以了
    全部程序:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Label1: TLabel;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    function escapeStr(src:string) :string;
    var
      i:integer;
      ret:string;
      ch:byte;
    begin
        i := length(src) ;
        ret :='';
        while  i > 0 do
        begin
         dec(i);
         ch := byte(src[i]);
            if (ch = 10) then
                ch := 15
             else if (ch = 13) then
                ch := 16
             else if (ch = 32) then
                ch := 17
             else if (ch = 9) then
                ch := 18
             else
                ch := ch + 5;
            ret := ret+char(ch);
        end;
        result:= ret;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage( escapeStr('a1234b'));
    end;end.
      

  4.   

    上面有个小问题,正确的函数为:
    function escapeStr(src:string) :string;
    var
      i:integer;
      ret:string;
      ch:byte;
    begin
        i := length(src) ;
        ret :='';
        while  i > 0 do
        begin
         ch := byte(src[i]);
            if (ch = 10) then
                ch := 15
             else if (ch = 13) then
                ch := 16
             else if (ch = 32) then
                ch := 17
             else if (ch = 9) then
                ch := 18
             else
                ch := ch + 5;
            ret := ret+char(ch);
         dec(i);
        end;
        result:= ret;
    end;
      

  5.   

    keiy() ,谢谢了,已经搞定了,呵呵