请问(10分)

  • 主题发起人 主题发起人 东方星辰
  • 开始时间 开始时间

东方星辰

Unregistered / Unconfirmed
GUEST, unregistred user!
1.我想给一个文件加密,请问如何实现,用什麽控件
2。在一个form中,左边有几个按钮,点击他之后,在同一Form中的右边出现他要调用的内容。请问如何实现
 
文件加密:请去参考{流文件}!!!
窗口调用:用dock(具体请查看帮助!!)
如:form1.dock(panel1,boundsrect);
 
不好意思,什麽是{流文件},你帮我简单说一下好吗
 
1.找个支持加密的压缩控件,ZIP类控件很多。自己找好了
2.。。。没看懂[:D]
 
1:新建一单元文件
unit Unit2;
interface
uses Classes;
type
Tmystream=class(Tfilestream)
private
fkey:string;
public
//constructor create(const filename:string;mode:word);
function read(var buffer;count:longint):longint;override;
function write(const buffer;count:longint):longint;override;
property key:string read fkey write fkey ;
end;
implementation
function Tmystream.write(const buffer;
count:longint):longint;
var
Pbu,Pmy,mykey:pchar;
i,enc:integer;
begin
getmem(pmy,count);
//为pmy分配内存
mykey:=pchar(key);
//将key转换为pchar指针
try
pbu:=pchar(@buffer);
//将buffer转换为pchar指针
for i:=0 to count-1 do

//将key的每个字符以此与buffer的
//每个字符循环相加,结果放入pmy指向的内存区
begin
enc:=(ord(pbu)+ord(mykey[(i mod length(key))])) mod 256;
Pmy:=char(enc);
end;
result:=inherited write(Pmy^,count);//将pmy指向的内容写入文件
finally
freemem(Pmy,count);
end;
end;
function Tmystream.read(var buffer;count:longint):longint;
var
Pbu,Pmy,mykey:pchar;
i,mycount,enc:integer;
begin
getmem(Pmy,count);//为pmy分配内存
mykey:=pchar(key);//将key转换为pchar指针
try
mycount:=inherited read(Pmy^,count);//将文件内容读入pmy指向内存区
Pbu:=Pchar(@buffer);//将buffer转换为pchar指针
for i:=0 to mycount-1 do
//将key的每个字符依次与pmy的每个字符循环相减,结果放入pbu指向的变量
begin
enc:=(ord(Pmy)-ord(mykey[(i mod length(key))])) mod 256;
Pbu:=chr(enc);
end;
finally
freemem(Pmy,count);
end;
result:=mycount;
end;
end.
新建一窗体
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Panel2: TPanel;
Panel3: TPanel;
Splitter1: TSplitter;
Panel4: TPanel;
Memo1: TMemo;
Memo2: TMemo;
Button4: TButton;
Label1: TLabel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
//将指定文件读入memo1
var
mystr:Tfilestream;
begin
if opendialog1.Execute then
begin
mystr:=Tfilestream.create(opendialog1.filename,fmopenread);
try
memo1.lines.LoadFromStream(mystr);
finally
mystr.Free;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
//将memo1中的内容加密,用指定文件名另存
var
encstr:Tmystream;
begin
if savedialog1.Execute then
begin
encstr:=Tmystream.create(savedialog1.filename,fmcreate);
encstr.key:=Edit1.Text;
try
memo1.lines.SaveToStream(encstr);
finally
encstr.Free;
end;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
//将选定的加密文件解开,读入memo2
var
encstr:Tmystream;
begin
if opendialog1.Execute then
begin
encstr:=Tmystream.create(opendialog1.filename,fmopenread);
encstr.key:=Edit1.Text;
try
memo2.lines.LoadFromStream(encstr);
finally
encstr.Free;
end;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;
end.

2:用panel控件
 
后退
顶部