1.调用API函数
procedure CopyFile(fromFileName,ToFileName:string);
var
f1,f2:file;
Begin
AssignFile(f1,fromFileName); file://指定源文件名
AssignFile(f2,ToFileName); file://指定目标文件名
Reset(f1);
Try
Rewrite(f2);
Try
If Lzcopy(TfileRec(f1).handle,TfileRec(f2).Handle)<0
Then
Raise EinoutError.creat('文件复制错误')
Finally
CloseFile(f2); file://关闭 f2
End;
Finally
Until length(sLine)<=0;
End;
End;
2.文件流
procedure copyfile;
var f1,f2: tfilestream ;
begin
f1:=Tfilestream.Create(sourcefilename,fmopenread);
try
f2:=Tfilestream.Create(targetfilename,fmopenwrite or fmcreate);
try
f2.Copyfrom(f1,f1.size);
finally
f2.Free;
end;
finally
f1.Free;
end;
end;
3.利用内存块读写buffer实现
Procudure FileCopy(const fromfile,Tofile:string);
Var
F1,F2:file;
NumRead,Numwritten:word;
Buf:array [1..2048] of char;
Begin
AssignFile(F1,fromfile);
Reset(F1,1);
AssignFile(F2,Tofile);
Rewrite(F2,1);
Repeat
BlockRead(F1,buf,sizeof(buf),NumRead);
BlockWr ......
在Delphi中,通常可以用以下三种方法来实现程序的延时,即TTtimer控件,Sleep函数,GetTickCount函数。但是其精度是各不相同的。
一、三种方法的简单介绍
1)TTtimer控件
TTtimer控件的实质是调用Windows API定时函数SetTimer和KillTimer来实现的,并简化了对WM_TIMER 消息的处理过程。通过设置OnTimer事
件和Interval属性,我们可以很方便的产生一些简单的定时事件。
2)Sleep函数
Sleep函数用来使程序的执行延时给定的时间值。Sleep的调用形式为Sleep(milliseconds),暂停当前的进程milliseconds毫秒。Sleep的实现
方法其实也是调用Windows API的Sleep函数。例如:
sleep(1000); //延迟1000毫秒
Sleep会引起程序停滞,如果你延迟的时间较长的话,你的程序将不能够响应延时期间的发生的其他消息,所以程序看起来好像暂时死机。
3)GetTickCount函数
在主程序中延时,为了达到延时和响应消息这两个目的,GetTickCount()构成的循环就是一种广为流传的方法。例如:
procedure Delay(MSecs: Longint);
//延时函数,MSecs单位为毫秒(千分之1秒)
var
FirstTickCount, Now: Longint;
begin
FirstTickCount ......
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses jpeg, GIFImg, pngimage;
{显示 jpg 图片}
procedure TForm1.Button1Click(Sender: TObject);
var
jpg: TJPEGImage;
begin
jpg := TJPEGImage.Create;
jpg.LoadfromFile('C:\Temp\Test.jpg');
Canvas.Draw(0, 0, jpg);
jpg.Free;
end;
{显示 png 图片}
procedure TForm1.Button2Click(Sender: TObject);
var
png: TPngImage;
begin
png := TPngImage.Create;
png.LoadfromFile('C:\Temp\Tes ......
注意:本文仅供技术交流,请勿用于非法用途。
要修改指定程序的指定地址数据,我们需要用到两个api函数,分别是ReadProcessMemory和WriteProcessMemory。
下载是函数的定义:
ReadProcessMemory
Reads data from an area of memory in a specified process. The entire area to be read must be accessible or the operation fails.
BOOL ReadProcessMemory( HANDLE hProcess, LPCVOID lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesRead);
Parameters
hProcess
[in] A handle to the process with memory that is being read. The handle must have PROCESS_VM_READ access to the process.
lpBaseAddress
[in] A pointer to the base address in the specified process from which to read. Before any data transfer occurs, the system verifies that all data in the base address and memory of the specified size is accessible for read access, and if it is not accessible the function fails.
lpBuffer
[out] A pointer to a buffer that receives the contents from the address space of the specified process. ......
利用内存流来判断文件的格式,其实判断文件的前几个字节就可以简单的判断这个文件是什么类型的文件。
procedure TFrm.CheckImgType(Sender: TObject);
var //声明变量
MyImage:TMemoryStream; //内存流对象
Buffer:Word;
i:integer;
begin
if OpenDialog1.Execute then //OpenDialog1是一个文件打开对话框
begin
MyImage:=TMemoryStream.Create; //建立内存流对象
try
MyImage.LoadfromFile(OpenDialog1.FileName); //把刚刚用户选择的文件载入到内存流中
MyImage.Position := 0; //移动指针到最开头的位置
if MyImage.Size = 0 then //如果文件大小等于0,那么
begin
ShowMessage('错误');
&nb ......
输入验证码 一个文本框 24字母随机出4个字母 然后用户
输入所随机出的字母 输入正确 进入界面。。错误又随机下。。。
*/
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
lbl1: TLabel;
Edit1: TEdit;
btn1: TButton;
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
function ShowRandom:string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
var
i,j:Integer;
c:Char;
begin
lbl1.Caption:=''; //这个是标签
for j:=0 to 3 do //随机生成4个a到z的字符串
begin
i:=Random(24);
c:=chr(ord('a') + i);
lbl1.Caption:=lbl1.Caption + c;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
if edit1.Text=lbl1.Caption then //成功
S ......