您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

Delphi中字符串隐藏写法(2)

时间:2011/9/3 15:35:50 点击:

代码:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

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 length(s)=0 then
        begin
           showmessage('Please input your string');
           exit;
        end;
    if length(t)=0 then
        begin
           showmessage('请输入变量名');
           exit;
        end;
    t:=Edit2.Text;
    wFileName:= 'ByTeCrypt.txt';
    AssignFile(wFile, wFileName);
    Rewrite(wFile);

    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,'  Showmessage('+t+');');
    Writeln(wFile,'end;');
    CloseFile(wFile);
    showmessage('执行完毕,请查看同目录下ByTeCrypt.txt文件!');

end;
end.

上一页12下一页

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号