📄 unit1.pas
字号:
unit Unit1;
interface
uses
SysUtils, Classes, DB, ADODB,IniFiles,Windows, Messages, Variants, Graphics, Controls, Forms,
Dialogs;
type
TDM = class(TDataModule)
con1: TADOConnection;
ADODataSet1: TADODataSet;
yhTable1: TADOTable;
DataSource1: TDataSource;
yhQuery1: TADOQuery;
qry1: TADOQuery;
qry2: TADOQuery;
ds1: TDataSource;
qry3: TADOQuery;
ds2: TDataSource;
qry4: TADOQuery;
ds3: TDataSource;
ds4: TDataSource;
tbl1: TADOTable;
tbl2: TADOTable;
tbl3: TADOTable;
ds5: TDataSource;
tbl4: TADOTable;
ds6: TDataSource;
qry5: TADOQuery;
ds7: TDataSource;
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
function Get_Db_Con_Str(FileName:String):String;
{ Public declarations }
end;
var
DM: TDM;
implementation
uses hkgl, unit2, Unit3, Unit4, Unit5, Unitjwh, Unitxqsz, Unitlcsz,
Unitczgl, Unitfjxx, Unitzhxx, Unitlxfs, Unitczgl1, Unittpld, Unit6,
Unit7, Unit8, Unithkxx, Unit9;
{$R *.dfm}
function Tdm.Get_Db_Con_Str(FileName:String):String;
var
ServerIP,SQLDBName,SQLUserName,SQLPwd:string;
begin
Result := '';
with TInifile.Create(Filename) do
begin
try
ServerIP:=ReadString('ServerInfo','ServerIP','');
SQLDBName:=ReadString('ServerInfo','SQLDBName','');
SQLUserName:=ReadString('ServerInfo','SQLUserID','');
SQLPwd:=ReadString('ServerInfo','SQLPwd','');
finally
Free;
end;
Result :='Provider=SQLOLEDB.1;Password='+SQLPwd+';Persist Security Info=True;User ID='+SQLUserName+
';Initial Catalog='+SQLDBName+';Data Source=' + ServerIP;
end;
end;
procedure TDM.DataModuleCreate(Sender: TObject);
var
Ini_FileName:String;
begin
Ini_FileName:=ExtractFilePath(application.ExeName)+'hkgl.ini';
if not FileExists(Ini_FileName) then
begin
ShowMessage('数据库连接配置文件不存在!');
Application.Terminate;
end;
with con1 do
begin
Connected := False;
ConnectionString:=Get_Db_Con_Str(Ini_FileName);
try
Connected := True;
//.....
//tbl1.Connection:='con1';
//tbl1.TableName:='hk_user'
//tbl1.Active:=True;
except
ShowMessage('数据库连接失败!请检查配置文件:'+Ini_FileName);
//....
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -