帮忙看看. (200分)

  • 主题发起人 主题发起人 coolcat
  • 开始时间 开始时间
C

coolcat

Unregistered / Unconfirmed
GUEST, unregistred user!
var
MenuItem:TMenuItem;
S:String;
begin
MenuItem:=Sender as TMenuItem;
Height:=22;
Width:=ACanvas.TextWidth(MenuItem.Caption)+25;
if MenuItem.Caption='-' then s:='';
if ShortCutToText(MenuItem.ShortCut)<>'' then
begin
Width:=Width+ACanvas.TextWidth(ShortCutToText(MenuItem.ShortCut));
s:=MenuItem.Caption;
s:=s+' '+ShortCutToText(MenuItem.ShortCut);
(Sender as TMenuItem).Caption:=s;
end;
end;
在Windows 2000下一运行就蓝屏..我试了3次蓝了三次.,
就是(Sender as TMenuItem).Caption:=s;这句的问题,去掉就不蓝了.

各位看看..怎么回事...
 
你的MenuItem变量没有初始化,又不是指针,所以……
 
我的
MenuItem:=Sender as TMenuItem;
这不是初始化吗?
Sender 是传过来的菜单项.
 
var
MenuItem:TMenuItem;
S:String;
begin
MenuItem:=TMenuItem(Sender) ;
If MenuItem=nil then
begin
showmesssage('對象沒有初始化');
exit;
end;
Height:=22;
Width:=ACanvas.TextWidth(MenuItem.Caption)+25;
if MenuItem.Caption='-' then s:='';
if ShortCutToText(MenuItem.ShortCut)<>'' then
begin
Width:=Width+ACanvas.TextWidth(ShortCutToText(MenuItem.ShortCut));
s:=MenuItem.Caption;
s:=s+' '+ShortCutToText(MenuItem.ShortCut);
MenuItem.Caption:=s;
end;
end;
這樣試一下
 
应该是你的(sender as TMeniItem)的错误
你的意思是想在(Sender as TMenuItem)下设置信息,可你有在本地设置一变量MenuItem
可能是delphi在处理你的时候发生冲突而至
 
我本来就是用MenuItem做的..可是蓝屏了.所以才改成(Sender as TMenuItem)的..
 
if MenuItem=nil then ShowMessage('nil');
证明对象已经初始化过了.
 
我估計你的sender對象傳進來可能不是菜單,你在過程的前面這樣加試一下:
If Sender=TMenuItem then
begin
showmesssage('菜單');
end;
 
If Sender=TMenuItem then
begin
showmesssage('菜單');
end;
证明是菜单没有错.
 
showmesssage(MenuItem.Caption);
如果這句都沒錯,那麼你應該檢查一下面的代碼
 
會不會你這個有錯:
ShortCutToText(MenuItem.ShortCut)
 
就是(Sender as TMenuItem).Caption:=s;这句的问题,去掉就不蓝了.
 
var
MenuItem:TMenuItem;
S:String;
begin
if not (Sender is TMenuItem) then Exit;
MenuItem:=TMenuItem(Sender);
Height:=22;
Width:=ACanvas.TextWidth(MenuItem.Caption)+25;
if MenuItem.Caption='-' then s:='';
if ShortCutToText(MenuItem.ShortCut)<>'' then
begin
Width:=Width+ACanvas.TextWidth(' '+ShortCutToText(MenuItem.ShortCut));
s:=MenuItem.Caption; /////计算宽度没有算下面的空格吧
s:=s+' '+ShortCutToText(MenuItem.ShortCut);
MenuItem.Caption:=s;
end;
end;
 
showmessage(s);//看看這個s是什麼東西,然後下面這樣寫;
MenuItem.Caption:=s;
 
to ysai:
不要管我计算空格没.我问的是为什么蓝屏..
 
不要教我怎么调试程序了..

我还会调试程序..
ShowMessage(S)输出的是正确的字符串..

我现在只想知道为什么蓝屏.
 
MenuItem.Caption:='ok' //這樣會不會藍屏?
 
不敢试了..
 
我猜你重画了什么,如果是,当然高度和宽度是用这个过程计算出来的,
应该不是Caption赋值的问题,你把它赋一个较小宽度的值或空字串应该不会出问题,
估计你少计算了宽度,所以太长的话就访问内存出错了,还有,这里的代码不是关键,
可能重画很难调试吧,重画过程里的没有做好错误处理,也就是蓝屏的原因
 
to ysai
胡说..

第一,我没有做任何重画的操作..
第二,字符串我输出看过的.根本没有问题.
 
后退
顶部