问一个不是问题的问题~~(10分)

L

logpie

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.N1Click(Sender: TObject);
var S1:string;
S2:string;
begin
S1:='ÔÝÍ£¼à²â';
S2:='¼ÌÐø¼ì²â';
if N1.Caption =S1 then

begin
N1.Caption :=s2;
timer1.Enabled :=false;
end;
if N1.Caption =S2 then
begin
N1.caption:=S1;
timer1.Enabled :=true;
end;
end;

N1为一POPUPMENU,CAPTION的值和S1相等,可执行N1。CLICK时N1。CAPTION死活不变成S2的值~
这到底是为什么?
 
在if N1.Caption =S1 then
前加:
showmessage(n1.caption);
看一下有没有执行,到底是什么?
 
程序有问题
if N1.Caption =S1 then

begin
N1.Caption :=s2;
timer1.Enabled :=false;
end;
执行完后,n1.caption:=s2
紧接着程序又执行
if N1.Caption =S2 then
begin
N1.caption:=S1;
timer1.Enabled :=true;
end;

n1.caption当然又变成s1了。
 
应改成下面的写法
procedure TForm1.N1Click(Sender: TObject);
var S1:string;
S2:string;
begin
S1:='ÔÝÍ£¼à²â';
S2:='¼ÌÐø¼ì²â';
if N1.Caption =S1 then

begin
N1.Caption :=s2;
timer1.Enabled :=false;
end
else
begin
N1.caption:=S1;
timer1.Enabled :=true;
end;
end;
 
你的 S1 和 S2 倒底是什么 ? 乱码。。
不过我猜想:
你的菜单是这样 文件(F)
你的 S1 := '文件(F)';
其实你的 S1 := '文件(&F)' 才跟有快捷键的菜单 Caption 匹配。。
你把你的 S1、S2 相对应的快捷键的字母前加上 &
试试呢?
 
procedure TForm1.N1Click(Sender: TObject);
var S1:string;
S2:string;
begin
S1:='ÔÝÍ£¼à²â';
S2:='¼ÌÐø¼ì²â';
if N1.Caption =S1 then

begin
N1.Caption :=s2;
timer1.Enabled :=false;
exit;
end;
if N1.Caption =S2 then
begin
N1.caption:=S1;
timer1.Enabled :=true;
end;
end;
 
To 火龙真人&auther:
你们的写法是我第一次使用的,并没有任何效果
 
procedure TForm1.N1Click(Sender: TObject);
var S1:string;
S2:string;
begin
S1:='ÔÝÍ£¼à²â';
S2:='¼ÌÐø¼ì²â';
if N1.Caption =S1 then

begin
N1.Caption :=s2;
timer1.Enabled :=false;
exit;
//退出,要不然会继续往下执行,又改回去了
end;
if N1.Caption =S2 then
begin
N1.caption:=S1;
timer1.Enabled :=true;
end;
end;
 
因为无法看到你s1和s2的具体值,还要注意像darnis说的那样有没有‘&’
其实设置断点,watch一下n1.caption的值就可以调试通过的。
 
S1,S2为2个任意值的STRING类型
POPUPMENU没有设置快截键
 
问题已解决,感谢auther和darnis的提醒
 
顶部