这是段INI to treer 的代码,别人的,你拿去研究研究,我用了下,还行。 procedure TForm1.Button1Click(Sender: TObject); var MyIniFile:TInifile; StrSections,StrSection:TStringList; i_Loop,j_Loop:Integer; ParentNode,ChildNode:TTreeNode; ParentCaption,ChildCaption:String; ParentVal,ChildVal:^String; Flag:integer; begin TreeView1.Items.Clear; Flag:=0; Try OpenDialog1.Execute; if not fFileExists(OpenDialog1.filename) then exit; MyIniFile:=TIniFile.Create(OpenDialog1.filename);
StrSections:=TStringList.Create; MyIniFile.ReadSections(StrSections); for i_Loop := 0 to StrSections.Count - 1 do begin Flag:=1; ParentCaption:=StrSections.Strings[i_Loop]; Try StrSection:=TStringList.Create; MyIniFile.ReadSection(ParentCaption,StrSection); New(ParentVal); ParentVal^:='这是段,有' + IntToStr(StrSection.Count) + '个变量'; ParentNode:=TreeView1.Items.Add(nil,'ParentCaption'); ParentNode.Text:=ParentCaption; ParentNode.Data:=ParentVal; for j_Loop := 0 to StrSection.Count - 1 do begin Flag:=2; ChildCaption:=StrSection.Strings[j_Loop]; New(ChildVal); ChildVal^:=MyIniFile.ReadString(StrSections[i_Loop],StrSection[j_Loop],''); ChildNode:=TreeView1.Items.AddChild(ParentNode,ChildCaption); ChildNode.Data:=ChildVal; end; Finally StrSection.Free; end; end; Finally if Flag > 1 then begin Dispose(ParentVal); Dispose(ChildVal); end else if Flag>0 then Dispose(ParentVal); StrSections.Free; MyIniFile.Free; end; end; end.
你给我一个详细的要求,我的Email:[email protected]
高红岩(ghyghost) 笔者近日在写ADO连接带密码的ACCESS数据库时,当connected:=true;时,总是出现密码不对的对话框,最终在研究了TADOConnection.ConnectionString的内容创建过程时得到灵感,现与大家分享。
1,新建Project。
2,在FORM中放入ADOConnection,ADOQuery,DataSource,Datagrid控件。
3,双击ADOConnection控件,然后点击Build...按钮,在“提供者”页中选择“Microsoft Jet 4.0 OLE DB Provider”,然后点击“下一步”按钮,在“连接”页中选择要连接的Access数据库的路径和数据库的文件名,这时如果点“测试连接”按钮时,出现“初始化提供者时发生错误,测试连接失败,密码无效”的错误提示。
4,这时点“所有”页,然后双击“Jet OLEDB:Database Password”,出现对话框,添入密码后,选择“连接”页中的“测试连接”按钮,出现“测试连接成功”的对话框。把ADOConnection控件的LoginPromtp设为false.
5,设置连接完成。
帮楼主UP
MainForm.adoquery.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;Password=123;Data Source=D:\DATA\data.mdb;Persist Security Info=True;试试可不可以!
procedure TForm1.Button1Click(Sender: TObject);
var
MyIniFile:TInifile;
StrSections,StrSection:TStringList;
i_Loop,j_Loop:Integer;
ParentNode,ChildNode:TTreeNode;
ParentCaption,ChildCaption:String;
ParentVal,ChildVal:^String;
Flag:integer;
begin
TreeView1.Items.Clear;
Flag:=0;
Try
OpenDialog1.Execute;
if not fFileExists(OpenDialog1.filename) then exit;
MyIniFile:=TIniFile.Create(OpenDialog1.filename);
StrSections:=TStringList.Create;
MyIniFile.ReadSections(StrSections);
for i_Loop := 0 to StrSections.Count - 1 do
begin
Flag:=1;
ParentCaption:=StrSections.Strings[i_Loop];
Try
StrSection:=TStringList.Create;
MyIniFile.ReadSection(ParentCaption,StrSection);
New(ParentVal);
ParentVal^:='这是段,有' + IntToStr(StrSection.Count) + '个变量';
ParentNode:=TreeView1.Items.Add(nil,'ParentCaption');
ParentNode.Text:=ParentCaption;
ParentNode.Data:=ParentVal;
for j_Loop := 0 to StrSection.Count - 1 do
begin
Flag:=2;
ChildCaption:=StrSection.Strings[j_Loop];
New(ChildVal);
ChildVal^:=MyIniFile.ReadString(StrSections[i_Loop],StrSection[j_Loop],'');
ChildNode:=TreeView1.Items.AddChild(ParentNode,ChildCaption);
ChildNode.Data:=ChildVal;
end;
Finally
StrSection.Free;
end;
end;
Finally
if Flag > 1 then
begin
Dispose(ParentVal);
Dispose(ChildVal);
end
else if Flag>0 then
Dispose(ParentVal); StrSections.Free;
MyIniFile.Free;
end;
end;
end.