Delphi 调用COM(VC编写)


Delphi 调用COM前的准备
--------------------------------------------------------------------
1. Windows 系统引入
运行 -> Regsvr32 x:/FCV.dll

x:/FCV.dll 是你放置COM文件的目录

2. Delphi 开发环境引入
Project -> Import Type Library ->"FCV 1.1 Type Library (Version1.1)"

 

主程序:

unit UntMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, OleServer, FCVLib_TLB; type TfrmMain = class(TForm) lblFileVal: TLabel; lblFcvVal: TLabel; edtFilePath: TEdit; btnGenFCN: TButton; edtFCVpath: TEdit; btnCalFileValue: TButton; btnReadFCV: TButton; btnCreatFCV: TButton; UCRC321: TUCRC32; procedure btnCreatFCVClick(Sender: TObject); procedure btnGenFCNClick(Sender: TObject); procedure btnCalFileValueClick(Sender: TObject); procedure btnReadFCVClick(Sender: TObject); private myFCV: IUCRC32; // 定义COM接口 { Private declarations } public instanceFlag: Boolean; { Public declarations } end; var frmMain: TfrmMain; implementation {$R *.dfm} procedure TfrmMain.btnCreatFCVClick(Sender: TObject); begin myFCV:= CoUCRC32.Create; instanceFlag := True; end; procedure TfrmMain.btnGenFCNClick(Sender: TObject); var saveFile, checkFile: WideString; i112: Integer; begin // if not instanceFlag then exit; saveFile:= edtFCVpath.Text; checkFile:= edtFilePath.Text; i112:= myFCV.SaveFCN(saveFile, checkFile); ShowMessage(inttostr(i112)); end; procedure TfrmMain.btnCalFileValueClick(Sender: TObject); var filePath: WideString; retVal: DWORD; begin if not instanceFlag then exit; filePath:= edtFilePath.Text; retVal:= myFCV.CalCRC32(filePath); lblFileVal.Caption:= IntToHex(retVal, 8); end; procedure TfrmMain.btnReadFCVClick(Sender: TObject); var filePath: WideString; retVal: DWORD; begin // if not instanceFlag then exit; filePath:= edtFCVpath.Text; retVal:= myFCV.ReadFCN(filePath); lblFcvVal.Caption:= IntToHex(retVal, 8); end; end.

 

 

我把整个工程文件上传到PUDN上了。

地址:http://www.pudn.com/downloads332/sourcecode/windows/activex/detail1458101.html

 

你可能感兴趣的:(windows,Class,import,library,Delphi,Forms)