procedure TMainForm.FormShow(Sender: TObject);
var
connini:TINIFile;
LocalDir:String;
sServer:String;
sBaseName:String;
sUserID:String;
sPassword:String;begin
GetDir(0,LocalDir);
//打开初始化文件,取得连接串参数
connini:=TINIFile.Create(LocalDir+'\shitangconn.ini');
sServer:=connini.ReadString('LogConn','ServerName','Error');
sBaseName:=connini.ReadString('LogConn','BaseName','Error');
sUserID:=connini.ReadString('LogConn','UserID','Error');
sPassword:=connini.ReadString('LogConn','Password','Error');
sConn:='Provider=SQLOLEDB.1;Persist Security Info=False;'+'User ID='+sUserID+';Password='+sPassword+';Initial Catalog='+sBasename+';Data Source='+sServer+';';
//连接串拼接完毕
ADOConnection1.Close;
ADOConnection1.ConnectionString:=sConn;
ADOConnection1.Open;
//使用查询取得部门名称,放入下拉列表中
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('SELECT distinct usewhere from paidrecord');
ADOQuery1.Open;
while not ADOQuery1.Eof do
begin
WhereCombo.Items.Add(ADOQuery1.FieldByName('usewhere').AsString);
ADOQuery1.Next;
end;
//查询断开
ADOQuery1.DisableControls;
ADOQuery1.Close;
DBGrid1.Enabled:=false;
//日期控件初始值设置为当前时间
Topicker.DateTime:=now;
Frompicker.DateTime:=now;
end;
var
connini:TINIFile;
LocalDir:String;
sServer:String;
sBaseName:String;
sUserID:String;
sPassword:String;begin
GetDir(0,LocalDir);
//打开初始化文件,取得连接串参数
connini:=TINIFile.Create(LocalDir+'\shitangconn.ini');
sServer:=connini.ReadString('LogConn','ServerName','Error');
sBaseName:=connini.ReadString('LogConn','BaseName','Error');
sUserID:=connini.ReadString('LogConn','UserID','Error');
sPassword:=connini.ReadString('LogConn','Password','Error');
sConn:='Provider=SQLOLEDB.1;Persist Security Info=False;'+'User ID='+sUserID+';Password='+sPassword+';Initial Catalog='+sBasename+';Data Source='+sServer+';';
//连接串拼接完毕
ADOConnection1.Close;
ADOConnection1.ConnectionString:=sConn;
ADOConnection1.Open;
//使用查询取得部门名称,放入下拉列表中
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('SELECT distinct usewhere from paidrecord');
ADOQuery1.Open;
while not ADOQuery1.Eof do
begin
WhereCombo.Items.Add(ADOQuery1.FieldByName('usewhere').AsString);
ADOQuery1.Next;
end;
//查询断开
ADOQuery1.DisableControls;
ADOQuery1.Close;
DBGrid1.Enabled:=false;
//日期控件初始值设置为当前时间
Topicker.DateTime:=now;
Frompicker.DateTime:=now;
end;
ini:TIniFile;
strpath:string;
begin
strPath := ExtractFilePath(Application.ExeName);
ini := TIniFile.Create(strPath + 'News.ini');
//记录窗口大小
ini.WriteInteger('Position','Left',Form1.Left);
ini.WriteInteger('Position','Top',Form1.Top);
ini.WriteInteger('Position','Width',Form1.Width);
ini.WriteInteger('Position','Height',Form1.Height);//记录控件大小、位置
ini.WriteInteger('TreeView','Width',TreeView1.Width);
end;
SelGroup:=Value;
inif.WriteString('Choosed','GroupIndex',Value);
inif.WriteInteger(SelGroup,'BackColor',AllColors[0]);
inif.WriteInteger(SelGroup,'RularColor',AllColors[1]);
inif.WriteInteger(SelGroup,'PFontColor',AllColors[2]);
inif.WriteInteger(SelGroup,'SunLineColor',AllColors[3]);
inif.WriteInteger(SelGroup,'ShadeLineColor',AllColors[4]);
inif.WriteInteger(SelGroup,'PlantColor',AllColors[5]);
inif.WriteInteger(SelGroup,'BrightColor',AllColors[6]);
inif.WriteInteger(SelGroup,'TargetLineColor1',AllColors[7]);
inif.WriteInteger(SelGroup,'TargetLineColor2',AllColors[8]);
inif.WriteInteger(SelGroup,'TargetLineColor3',AllColors[9]);
inif.WriteInteger(SelGroup,'TargetLineColor4',AllColors[10]);
inif.WriteInteger(SelGroup,'TargetLineColor5',AllColors[11]);
inif.WriteInteger(SelGroup,'TargetLineColor6',AllColors[12]);
inif.WriteInteger(SelGroup,'UpFontColor',AllColors[13]);
inif.WriteInteger(SelGroup,'HerFontColor',AllColors[14]);
inif.WriteInteger(SelGroup,'DownFontColor',AllColors[15]);
inif.WriteInteger(SelGroup,'SelectColor',AllColors[16]);
inif.WriteInteger(SelGroup,'GridLineColor',AllColors[17]);
inif.WriteInteger(SelGroup,'LineColor',AllColors[18]);
inif.WriteString(SelGroup, 'FontPName',FontP.Name);
inif.WriteInteger(SelGroup,'FontPSize',FontP.size);
inif.WriteString(SelGroup, 'FontGName',FontG.Name);
inif.WriteInteger(SelGroup,'FontGSize',FontG.size);
////////////写入一些内容
Selgroup:=ExtractFilePath((Application.ExeName));
inif:=Tinifile.Create(Selgroup+'Colors.ini');
if Value='' then
SelGroup:=inif.ReadString('Choosed','GroupIndex','红黑')
else
SelGroup:=Value;
SComBobox.Text:=SelGroup;
AllColors[0]:=inif.ReadInteger(SelGroup,'BackColor',clBlack);
AllColors[1]:=inif.ReadInteger(SelGroup,'RularColor',clMaroon);
AllColors[2]:=inif.ReadInteger(SelGroup,'PFontColor',clWhite);
AllColors[3]:=inif.ReadInteger(SelGroup,'SunLineColor',5263615);
AllColors[4]:=inif.ReadInteger(SelGroup,'ShadeLineColor',16776960);
AllColors[5]:=inif.ReadInteger(SelGroup,'PlantColor',16777215);
AllColors[6]:=inif.ReadInteger(SelGroup,'BrightColor',clyellow);
AllColors[7]:=inif.ReadInteger(SelGroup,'TargetLineColor1',16711935);
AllColors[8]:=inif.ReadInteger(SelGroup,'TargetLineColor2',65535);
AllColors[9]:=inif.ReadInteger(SelGroup,'TargetLineColor3',65280);
AllColors[10]:=inif.ReadInteger(SelGroup,'TargetLineColor4',clWhite);
AllColors[11]:=inif.ReadInteger(SelGroup,'TargetLineColor5',-2147483645);
AllColors[12]:=inif.ReadInteger(SelGroup,'TargetLineColor6',16711680);
AllColors[13]:=inif.ReadInteger(SelGroup,'UpFontColor',5263615);
AllColors[14]:=inif.ReadInteger(SelGroup,'HerFontColor',clSilver);
AllColors[15]:=inif.ReadInteger(SelGroup,'DownFontColor',16776960);
AllColors[16]:=inif.ReadInteger(SelGroup,'SelectColor',clblue);
AllColors[17]:=inif.ReadInteger(SelGroup,'GridLineColor',clMaroon);
AllColors[18]:=inif.ReadInteger(SelGroup,'LineColor',clRed);
//读一些
uses INIFiles
程序结束前记得free
方法有:
Create
DeleteKey
EraseSection
ReadBool
ReadInteger
ReadSection
ReadSections
ReadSectionValues
ReadString
WriteBool
WriteInteger
WriteString
属性有:FileName用WinAPI
GetPrivateProfileSection
WritePrivateProfileSection
GetProfileInt
...
var sysini:Tinifile;
begin
sysini:=Tinifile.create(thefilepath+'\XX.ini');
result:=sysini.readstring(thesection,thekeyname,'');
sysini.free;
end;procedure writeinfotosysini(thesection,thekeyname,thefilepath,thevalue:string);
var
sysini:Tinifile;
beign
sysini:=Tinifile.create(thefilepath+'\xx.ini');
sysini.writestring(thesection,thekeyname,thevalue);
sysini.free;
end;
//说明:
ini格式 :[insys]
aaa=3
//调用时thesection=‘insys’,thekeyname=‘aaa'
2、声明一个Ini变量:Ini : TIniFile;
3、创建Ini对象:Ini := TiniFile.Create( FileName );
4、读写Ini文件,具体参考帮助
5、释放Ini对象:Ini.Free;