Use Delphi to write DLLs that can be called by other languages

Source: Internet
Author: User
Tags file copy

In the application software that is open, sometimes we copy some files (such as backing up the database, making the installer), but some languages that are commonly used do not provide a procedure or function that can directly copy the files. To this end, I used Delphi to develop a file copy process to provide a dynamic connection library Copy.dll, the output process is copyfile. Because the DLL has many advantages, such as simplifying programming and running fast, and is not limited by the programming language,

Delphi written by the Copf.dll is also VB, VC and other object-oriented language for static or dynamic calls, people and conveniently in the program to achieve file copies.

The attached source procedure is as follows:

library copf;
uses
SysUntils,Classes;
procedure copyfile(Sfname.Dfname:string):far;export;//带路径的文件名;
Var
Sourcef,Destinef:file;
NumRead,NumWritten:Integer;
Buf:array[1..4096] of char;//定义缓冲区;
Begin
AssignFile(Sourcef,dfname);
Reset(Sourcef,1);
AssignFile(Destinef,1);
Rewrite(Destinef,1);
Repeat
BlockRead(Sourcef,Buf,SizeOf(Buf),Numread);//读源文件
BlockWrite(destinef,buf,NumRead,NumWritten);//写目标文件;
Until (Numread=0) or (Numwritten<>numread);
closeFile(soucef);
Closefile(destinef);
end;
Esports

copyfile;//output process;

End

The above source program compiles and then generates Copf.dll

Now, for example, static invocation:

unit Name;
interface
uses
Windows...;
Type
Tzcform=class(Tform)
...
end;
var
Form1:Tform1;
implementation
Procedure copyfile(Sfname,dfname:string);far;external'c:\copf';//DLL路径名;
{$R *.DFM}
Procedure Tform1.CopyButtonclick(sender:tobject);
Begin
...
if fileesist(sfname)//如果源文件;
then copyfile(sfname,dfname);
... end;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.