procedure HiddenByName(Name:string;Parent:TMenuItem); var i:integer; begin for i:=0 to Parent.Count-1 do if CompareText(Parent.Items[i].Caption,Name)=0 then begin Parent.Items[i].Visible:=false; exit;//如果你要把所有和AName相同的都隐藏掉。去掉这个exit就可以了 end; end;HiddenByName(Edit1.Caption,NWE);
些错了: HiddenByName(Edit1.Text,NWE);
procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin for i:=0 to MainMenu1.Items[0].Count-1 do begin if MainMenu1.Items[0].Items[i].Caption=edit1.Text then MainMenu1.Items[0].Items[i].Visible:=false; end; end; 这个可以吗?
procedure TForm1.Button1Click(Sender: TObject); var i,j:integer; begin for j:=0 to MainMenu1.items.count-1 do begin if MenuItem1.Items[J].Caption := '你想隐藏菜单顶层的名字' then begin for i:=0 to MainMenu1.Items[0].Count-1 do begin if MainMenu1.Items[0].Items[i].Caption=edit1.Text then MainMenu1.Items[0].Items[i].Visible:=false; end; end; end; 不会还出错吧?
呵呵,我还说nyf1220这家伙怎么研究起这个来了,闹了半天是看了这个帖子。呵呵....procedure TForm1.Button1Click(Sender: TObject); var I:Integer; ItemCaption:String; begin for I:=0 to MainMenu1.Items[0].Count-1 do begin ItemCaption:=MainMenu1.Items[0].Items [I].Caption ; Delete(ItemCaption,Pos('&',ItemCaption),1); if ItemCaption=Trim(Edit1.Text) then MainMenu1.Items[0].Items[I].Visible:=False; end; end;揭贴吧,楼主!
var i:integer;
begin
for i:=0 to Parent.Count-1 do
if CompareText(Parent.Items[i].Caption,Name)=0 then
begin
Parent.Items[i].Visible:=false;
exit;//如果你要把所有和AName相同的都隐藏掉。去掉这个exit就可以了
end;
end;HiddenByName(Edit1.Caption,NWE);
HiddenByName(Edit1.Text,NWE);
var
i:integer;
begin
for i:=0 to MainMenu1.Items[0].Count-1 do
begin
if MainMenu1.Items[0].Items[i].Caption=edit1.Text then
MainMenu1.Items[0].Items[i].Visible:=false;
end;
end;
这个可以吗?
但是比两个UpperCase后的字符串比较又要更加有效率。
但是比两个UpperCase后的字符串比较又要更加有效率。
var
i,j:integer;
begin
for j:=0 to MainMenu1.items.count-1 do
begin
if MenuItem1.Items[J].Caption := '你想隐藏菜单顶层的名字' then
begin
for i:=0 to MainMenu1.Items[0].Count-1 do
begin
if MainMenu1.Items[0].Items[i].Caption=edit1.Text then
MainMenu1.Items[0].Items[i].Visible:=false;
end;
end;
end;
不会还出错吧?
var
I:Integer;
ItemCaption:String;
begin
for I:=0 to MainMenu1.Items[0].Count-1 do
begin
ItemCaption:=MainMenu1.Items[0].Items [I].Caption ;
Delete(ItemCaption,Pos('&',ItemCaption),1);
if ItemCaption=Trim(Edit1.Text) then
MainMenu1.Items[0].Items[I].Visible:=False;
end;
end;揭贴吧,楼主!