为啥读不出INI内容呢?
procedure TBandForm.IniMenu;
var
i, j: integer;
MI: TMenuItem;
pMD: TpMenuData;
Section: string;
pListItem: TpListItem;
begin
MainIndex := 0;
CategoryList := TList.Create;
ini:=Tinifile.create(AppDir+'\SearchUrl.ini');
Config.WebSite := ini.ReadInteger('Config','WebSite',0);
Config.EngineCount := ini.ReadInteger('Config','EngineCount',0);
Config.WriteLog := ini.ReadInteger('Config','WriteLog',0);
Config.AutoSearch := ini.ReadInteger('Config','AutoSearch',0);
SetLength(MD,Config.EngineCount);
for i := 0 to Config.EngineCount-1 do
begin
//new(pMD);
pMD := @MD[i];
Section := inttostr(i);
pMD.Name := ini.ReadString(Section,'Name','');
pMD.Category := ini.ReadString(Section,'Category','');
pMD.HomePage := ini.ReadString(Section,'HomePage','');
pMD.URL := ini.ReadString(Section,'URL',''); GetCategory(pMD.Category);
for j:= 0 to CategoryList.Count-1 do
begin
pListItem := TpListItem(CategoryList.Items[j]);
if pos(pListItem.Category,pMD.Category)<>0 then // is this category
begin
MI := TMenuItem.Create(self);
MI.AutoHotkeys := maManual;
MI.Caption := pMD.Name;
MI.Tag := integer(pMD);
MI.OnClick := MyMenuHandler;
pListItem.menu.Add(MI); end;
end;
end;
end;procedure TBandForm.MyMenuHandler(Sender: TObject);
var
pMD: TpMenuData;
begin
With sender as TMenuItem do
begin
pMD := TpMenuData(tag);
ShowMessage(pMD.HomePage+#13+pMD.URL);
tbSearchType.Caption := pMD.Name;
pCurData := pMD;
if trim(cbAddr.Text) <> '' then tbGoClick(Self);
end;
end;procedure TBandForm.GetCategory(s: string);
var
i, j, len, index: integer;
ts: string;
pListItem: TpListItem;
bExist: boolean;
begin
ts := '';
len := length(s);
index := 0;
for i := 1 to len do
begin
if s[i]<>';' then ts:=ts+s[i];// else inc(index);
if (s[i]=';')or(i=len) then
if trim(ts)<>'' then
begin
bExist := false;
for j:= 0 to CategoryList.Count-1 do
begin
pListItem := TpListItem(CategoryList.Items[j]);
if ts = pListItem.Category then
begin
bExist := true;
break;
end;
end;
if not bExist then
begin
new(pListItem);
pListItem.Category := ts;
pListItem.menu := TMenuItem.Create(self);
//pListItem.menu.AutoHotkeys := maManual;
pListItem.menu.Caption := ts;
//pListItem.menu.ShortCut := ;
//pListItem.menu.OnClick := MyMenuHandler;
if index = 0 then
begin
mSearch.Insert(MainIndex,pListItem.menu);
inc(MainIndex);
end
else
mSearch.Add(pListItem.menu);
CategoryList.Add(pListItem);
end;
inc(index);
ts:='';
end;
end;
end; ------------------------------------------------------------------------------------ini文件的内容是这样的[HKEY_USERS\S-1-5-21-117609710-515967899-725345543-500\Software\BingleToolbar]
"WebSite"=dword:00000002
"EngineCount"=dword:00000011
"WriteLog"=dword:00000001
"AutoSearch"=dword:00000001[HKEY_USERS\S-1-5-21-117609710-515967899-725345543-500\Software\BingleToolbar\0]
"Name"="天网"
"Category"="软件搜索"
"HomePage"="http://bingle.pku.edu.cn/"
"URL"="http://bingle.pku.edu.cn/scripts/ftp_search.exe?word="
procedure TBandForm.IniMenu;
var
i, j: integer;
MI: TMenuItem;
pMD: TpMenuData;
Section: string;
pListItem: TpListItem;
begin
MainIndex := 0;
CategoryList := TList.Create;
ini:=Tinifile.create(AppDir+'\SearchUrl.ini');
Config.WebSite := ini.ReadInteger('Config','WebSite',0);
Config.EngineCount := ini.ReadInteger('Config','EngineCount',0);
Config.WriteLog := ini.ReadInteger('Config','WriteLog',0);
Config.AutoSearch := ini.ReadInteger('Config','AutoSearch',0);
SetLength(MD,Config.EngineCount);
for i := 0 to Config.EngineCount-1 do
begin
//new(pMD);
pMD := @MD[i];
Section := inttostr(i);
pMD.Name := ini.ReadString(Section,'Name','');
pMD.Category := ini.ReadString(Section,'Category','');
pMD.HomePage := ini.ReadString(Section,'HomePage','');
pMD.URL := ini.ReadString(Section,'URL',''); GetCategory(pMD.Category);
for j:= 0 to CategoryList.Count-1 do
begin
pListItem := TpListItem(CategoryList.Items[j]);
if pos(pListItem.Category,pMD.Category)<>0 then // is this category
begin
MI := TMenuItem.Create(self);
MI.AutoHotkeys := maManual;
MI.Caption := pMD.Name;
MI.Tag := integer(pMD);
MI.OnClick := MyMenuHandler;
pListItem.menu.Add(MI); end;
end;
end;
end;procedure TBandForm.MyMenuHandler(Sender: TObject);
var
pMD: TpMenuData;
begin
With sender as TMenuItem do
begin
pMD := TpMenuData(tag);
ShowMessage(pMD.HomePage+#13+pMD.URL);
tbSearchType.Caption := pMD.Name;
pCurData := pMD;
if trim(cbAddr.Text) <> '' then tbGoClick(Self);
end;
end;procedure TBandForm.GetCategory(s: string);
var
i, j, len, index: integer;
ts: string;
pListItem: TpListItem;
bExist: boolean;
begin
ts := '';
len := length(s);
index := 0;
for i := 1 to len do
begin
if s[i]<>';' then ts:=ts+s[i];// else inc(index);
if (s[i]=';')or(i=len) then
if trim(ts)<>'' then
begin
bExist := false;
for j:= 0 to CategoryList.Count-1 do
begin
pListItem := TpListItem(CategoryList.Items[j]);
if ts = pListItem.Category then
begin
bExist := true;
break;
end;
end;
if not bExist then
begin
new(pListItem);
pListItem.Category := ts;
pListItem.menu := TMenuItem.Create(self);
//pListItem.menu.AutoHotkeys := maManual;
pListItem.menu.Caption := ts;
//pListItem.menu.ShortCut := ;
//pListItem.menu.OnClick := MyMenuHandler;
if index = 0 then
begin
mSearch.Insert(MainIndex,pListItem.menu);
inc(MainIndex);
end
else
mSearch.Add(pListItem.menu);
CategoryList.Add(pListItem);
end;
inc(index);
ts:='';
end;
end;
end; ------------------------------------------------------------------------------------ini文件的内容是这样的[HKEY_USERS\S-1-5-21-117609710-515967899-725345543-500\Software\BingleToolbar]
"WebSite"=dword:00000002
"EngineCount"=dword:00000011
"WriteLog"=dword:00000001
"AutoSearch"=dword:00000001[HKEY_USERS\S-1-5-21-117609710-515967899-725345543-500\Software\BingleToolbar\0]
"Name"="天网"
"Category"="软件搜索"
"HomePage"="http://bingle.pku.edu.cn/"
"URL"="http://bingle.pku.edu.cn/scripts/ftp_search.exe?word="
解决方案 »
- 倒在Activex弹窗下的webbrowser!!!!!!!!!!!!!!!!
- 解决了这个问题要多少分我都给,先给100分!
- 傷心的delphi菜鳥﹗散分﹗
- fastreport!!!
- 如何读写bmp.PixelFormat :=pf4bit ( 16色)的图各点颜色?
- 如何实现金山词霸2002启动时的效果?
- 迟到啦,第二课,打印,嘻嘻嘻,高的,别来啦,俺怕涮,嘻嘻嘻
- 声讨万网,我现在被万网气得吐血
- 高手呢?? 我的分值没多少了呀? 帮助我解决问题呀!返回PrinterSetupDialog(PrinterDialog)选择的打印机名字怎么写?
- 如何获得系统的应用程序?
- 请问如何将一个长度为Len的Pointer变量,拆分成十段,然后再合并起来?
- Delphi分不分Debug和Release?
Config.WebSite := ini.ReadInteger('HKEY_USERS\S-1-5-21-117609710-515967899-725345543-500\Software\BingleToolbar','WebSite',0);
'HKEY_USERS\S-1-5-21-117609710-515967899-725345543-500\Software\BingleToolbar这个注册表的东西要不要无所谓吧,主要是读下面这些,
"Name"="天网"
"Category"="软件搜索"
"HomePage"="http://bingle.pku.edu.cn/"
"URL"="http://bingle.pku.edu.cn/scripts/ftp_search.exe?word="
TPMEUNDATA也要定义好象是这个吧
TPMEUNDATA=RECORD
Name:STRING;
Category:STRING;
HomePage:STRING;
URL :STRING;
ENDini文件也要放到程序目录下
其他都是程序,你检查下,看哪里还出错
type
TConfig = record
WebSite: integer;
EngineCount: integer;
WriteLog: integer;
AutoSearch: integer;
end; TpMenuData = ^TMenuData;
TMenuData = record
Name: string;
Category: string;
HomePage: string;
URL: string;
end; TpListItem = ^TListItem;
TListItem = record
Category: string;
menu: TMenuItem;
end;
好象啥也没从INI里读出来~
麻烦您看一下,谢谢了~
"Category"="软件搜索"
"HomePage"="http://bingle.pku.edu.cn/"
"URL"="http://bingle.pku.edu.cn/scripts/ftp_search.exe?word="
我是想把这些东西都读到菜单中,它原来的程序中动态的这段也是没出来,里面用的是直接写的一个Menu,能麻烦您帮我改一下么?小弟不胜感激,我可以再加分给您~谢谢了~
var
aMD:TMainMenu;
NewItem:TMenuItem;
i:Integer;
MyList:TStringlist;
begin
Mylist:=TStringList.Create;
MyLIst.Add('ss'); //如果你想从ini读,那么把ini里信息保存到这里也行,自己看着转化吧,
MyLIst.Add('ddd');
MyList.Add('saff');
aMD:=TMainMenu.Create(Self);
for i:=0 to Mylist.Count-1 do
begin
NewItem:=TMenuItem.Create(Self);
NewItem.Caption:=MyList.Strings[i];
if aMD.Items.Count=0 then
aMD.Items.Add(NewItem)
else
aMD.Items.Items[0].Add(NewItem);
end;
end;
"WebSite"=dword:00000002
"EngineCount"=dword:00000011
"WriteLog"=dword:00000001
"AutoSearch"=dword:00000001[sectionname]
"Name"="天网"
"Category"="软件搜索"
"HomePage"="http://bingle.pku.edu.cn/"
"URL"="http://bingle.pku.edu.cn/scripts/ftp_search.exe?word="你主要是从文件读取的函数参数不熟,搞清楚参数含义就没问题了.
[section]
"Name"="天网"
"Category"="软件搜索"
"HomePage"="http://bingle.pku.edu.cn/"
"URL"="http://bingle.pku.edu.cn/scripts/ftp_search.exe?word="是不是这里有问题:
for i := 0 to Config.EngineCount-1 do
begin
//new(pMD);
pMD := @MD[i];
Section := inttostr(i);
pMD.Name := ini.ReadString(Section,'Name','');
pMD.Category := ini.ReadString(Section,'Category','');
pMD.HomePage := ini.ReadString(Section,'HomePage','');
pMD.URL := ini.ReadString(Section,'URL',''); GetCategory(pMD.Category);
for j:= 0 to CategoryList.Count-1 do
begin
pListItem := TpListItem(CategoryList.Items[j]);
if pos(pListItem.Category,pMD.Category)<>0 then // is this category
begin
MI := TMenuItem.Create(self);
MI.AutoHotkeys := maManual;
MI.Caption := pMD.Name;
MI.Tag := integer(pMD);
MI.OnClick := MyMenuHandler;
pListItem.menu.Add(MI); end;
end;