如何在系统的工程文件中,加入函数?要具体的格式

ctrlqrj 2003-09-12 12:32:08
如题:
想在程序的启动时,通过函数获取硬盘的序列号,来判断是否启动程序。
...全文
86 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawnming 2003-09-13
  • 打赏
  • 举报
回复
帮你up一下
我原本不是一头猪
Little2000 2003-09-13
  • 打赏
  • 举报
回复
File--New--Unit
然后在里面写入自己的程序,例如:
unit CommonFunction;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls, ComCtrls, ExtCtrls;

Type
TSearchFields = Array of String;

var
SearchFields: TSearchFields;
Procedure CreateSearchForm;//声明自己的函数

uses SetSearch;

Procedure CreateSearchForm;//写函数的具体内容
begin
Application.CreateForm(TFrmSetSearch,FrmSetSearch);
FrmSetSearch.ShowModal;
end;

end;

该单元和一般的单元文件一样,只是没有窗体文件而已,主要要在工程单元中引用该单元,然后就可以调用该单元的任何函数了。
hiflower 2003-09-12
  • 打赏
  • 举报
回复

begin
Application.Initialize;
if 检查通过 then
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
Application.Terminate;
end.
dickeybird888 2003-09-12
  • 打赏
  • 举报
回复
unit Utility;

interface

uses Classes,Sysutils,TrPanel,forms,Windows,DBTables,Registry,Db;

function MonthBegin(Date:TDateTime):TDateTime; //月开始日期
function MonthEnd(Date:TDateTime):TDateTime; //月结束日期

//以下定义全局变量

var
Tool:TTool;
BasicInfoTableName:String;

const
AppName='管理系统';
AppVersion ='版本1.0';



implementation


///////////////////////////////////////////////////////////////////////////
// 功能:获得某日期所在月份的第一天 //
// 入口参数:TDateTime 某日期 //
// 返回值: 某日期所在月份的第一天 //
///////////////////////////////////////////////////////////////////////////
function MonthBegin(Date:TDateTime):TDateTime;
var
T:String;
var
Year, Month, Day{, Hour, Min, Sec, MSec}: Word;
begin
DecodeDate(Date, Year, Month, Day);
T:=IntToStr(Year)+'-'+IntToStr(Month)+'-';
Result:=StrToDate(T+'1')
end;

///////////////////////////////////////////////////////////////////////////
// 功能:获得某日期所在月份的最后一天 //
// 入口参数:TDateTime 某日期 //
// 返回值: 某日期所在月份的最后一天 //
///////////////////////////////////////////////////////////////////////////
function MonthEnd(Date:TDateTime):TDateTime;
var
Year, Month, Day{, Hour, Min, Sec, MSec}: Word;
T:String;
begin
Result:=0;
DecodeDate(Date, Year, Month, Day);
T:=IntToStr(Year)+'-'+IntToStr(Month)+'-';
case Month of
1,3,5,7,8,10,12:Result:=StrToDate(T+'31');
4,6,9,11 :Result:=StrToDate(T+'30');
2 :if (Year mod 4 =0) and ( Year mod 100 <> 0 )
or (Year mod 400 =0 )
then
Result:=StrToDate(T+'29')
else
Result:=StrToDate(T+'28');
end;
end;


end.

Drate 2003-09-12
  • 打赏
  • 举报
回复

{$R *.res}


function ConnectStrNull:Boolean;
var
SYSINI: TINIFile;
tmpstr:String;
begin
Result:= True;
SYSINI := TIniFile.Create(ExtractFilePath(Application.ExeName)+'DB.INI');
try
tmpstr:= SYSINI.ReadString('Database', 'DBName', '');
if tmpstr ='' then
exit;
tmpstr:= SYSINI.ReadString('Database', 'UserName', '');
if tmpstr ='' then
exit;
Result:= False;
finally
SYSINI.Free;
end;
end;

begin
Application.Initialize;
Application.Title := '客户端物流管理系统';
if ConnectStrNull then
begin
{...}
MCLITAO 2003-09-12
  • 打赏
  • 举报
回复
别忘了引用单元文件名,就是函数所在的单元。
Delphi_Li 2003-09-12
  • 打赏
  • 举报
回复
就象写一般的函数一样!!!
Function XXXX : Boolean
Begin
.....
End;

begin
Application.Initialize;
if XXXX then
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
Application.Terminate;
end.
ctrlqrj 2003-09-12
  • 打赏
  • 举报
回复
对了,我要的就是单元库文件中的格式如何写,能贴个上来吗?
Little2000 2003-09-12
  • 打赏
  • 举报
回复
你可以将函数写到一个单元库文件中,然后就可以在工程中进行调用了
hongqi162 2003-09-12
  • 打赏
  • 举报
回复
up 楼上

5,385

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧