TMyStructure2
    Fiest:TMyStructure1;
    Second:TMyStructure1;
    Third:TMyStructure1;
    Fourth:TMyStructure1;
   在之后我想定义一个GetALL函数,返回Fiest,Second,Third,Fourth的总和.
请问这个类怎么定义好哪?

解决方案 »

  1.   

    unit XORCrypt;interfaceuses
      SysUtils, Classes;type
      TXORCrypt = class(TComponent)
      private
        { Private declarations }
        FKey:string;
        procedure SetKey(const AValue:string);    function myStrtoHex(s:string):string;                     //原字符串转16进制字符串
        function myHextoStr(S: string): string;                    //16进制字符串转原字符串
      protected
        { Protected declarations }
      public
        { Public declarations }
        //加密,解密方法是通过 【异或加密】,【异或解密】
        //function encryptstr(const s:string; skey:string):string;  //加密,返回加密后的字符串
        //function decryptstr(const s:string; skey:string):string;  //解密,返回解密后的字符串
        function encryptstr(const s:string):string;  //加密,返回加密后的字符串
        function decryptstr(const s:string):string;  //解密,返回解密后的字符串    constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;  published
        { Published declarations }
        property Key:string read FKey write SetKey;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('CY', [TXORCrypt]);
    end;constructor TXORCrypt.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FKey:='Yeeyee';
    end;destructor TXORCrypt.Destroy;
    begin
      inherited Destroy;
    end;procedure TXORCrypt.SetKey(const AValue:string);
    begin
      if FKey<>AValue then
      begin
        FKey:=AValue;
      end;
    end;//原字符串转16进制字符串
    function TXORCrypt.myStrtoHex(s: string): string;
    var
      tmpstr:string;
      i:integer;
    begin
      tmpstr := '';
      for i:=1 to length(s) do
      begin
        tmpstr := tmpstr + inttoHex(ord(s[i]),2);
      end;
      result := tmpstr;
    end;//16进制字符串转原字符串
    function TXORCrypt.myHextoStr(S: string): string;
    var
      hexS,tmpstr:string;
      i:integer;
      a:byte;
    begin
      hexS  :=s;//应该是该字符串
      if length(hexS) mod 2=1 then
      begin
        hexS:=hexS+'0';
      end;
      tmpstr:='';
      for i:=1 to (length(hexS) div 2) do
      begin
        a:=strtoint('$'+hexS[2*i-1]+hexS[2*i]);
        tmpstr := tmpstr+chr(a);
      end;
      result :=tmpstr;
    end;//加密
    // function TXORCrypt.encryptstr(const s:string; skey:string):string;
    function TXORCrypt.encryptstr(const s:string):string;
    var
      i,j: integer;
      hexS,hexskey,midS,tmpstr:string;
      a,b,c:byte;
    begin
      hexS   :=myStrtoHex(s);
      hexskey:=myStrtoHex(FKey);
      midS   :=hexS;
      for i:=1 to (length(hexskey) div 2)   do
      begin
        if i<>1 then
        begin
          midS:= tmpstr;
        end;
        tmpstr:='';
        for j:=1 to (length(midS) div 2) do
        begin
          a:=strtoint('$'+midS[2*j-1]+midS[2*j]);
          b:=strtoint('$'+hexskey[2*i-1]+hexskey[2*i]);
          c:=a xor b;
          tmpstr := tmpstr+myStrtoHex(chr(c));
        end;
      end;
      result := tmpstr;
    end;//解密
    // function TXORCrypt.decryptstr(const s:string; skey:string):string;
    function TXORCrypt.decryptstr(const s:string):string;
    var
      i,j: integer;
      hexS,hexskey,midS,tmpstr:string;
      a,b,c:byte;
    begin
      hexS  :=s;//应该是该字符串
      if length(hexS) mod 2=1 then
      begin
        //showmessage('密文错误!');
        exit;
      end;
      hexskey:=myStrtoHex(FKey);
      tmpstr :=hexS;
      midS   :=hexS;
      for i:=(length(hexskey) div 2) downto 1 do
      begin
        if i<>(length(hexskey) div 2) then
        begin
          midS:= tmpstr;
        end;
        tmpstr:='';
        for j:=1 to (length(midS) div 2) do
        begin
          a:=strtoint('$'+midS[2*j-1]+midS[2*j]);
          b:=strtoint('$'+hexskey[2*i-1]+hexskey[2*i]);
          c:=a xor b;
          tmpstr := tmpstr+myStrtoHex(chr(c));
        end;
      end;
      result := myHextoStr(tmpstr);
    end;
    end.
      

  2.   

    type
    TMyStructure2=class
        Fiest:TMyStructure1;
        Second:TMyStructure1;
        Third:TMyStructure1;
        Fourth:TMyStructure1;
        private:    Public:   end;建议看看基础
      

  3.   

    基础问题哦
    看书去http://lysoft.7u7.net