Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.01.01;
Скачать: CL | DM;

Вниз

Menu bug   Найти похожие ветки 

 
Thaddy   (2005-05-12 10:30) [0]

Martin Larsen brought a bug with menu"s to my attention.
If you add a submenu while the menu contains an invisible item, it looses track and does not display a caption.

A description and demo is here:
http://martin.larsen.homepage.dk/MenuBug2.zip

A work around is to :
1) make the invisible items also disabled
2) check for disabled before dynamically adding the submenu
3) set disabled items to visible before adding
4) add the submenu
5) set disbled items to invisible again.

[CODE]
procedure TForm1.CheckBox1Click(Sender: PObj);
begin
 P.Items[0].enabled := CheckBox1.Checked;
 P.Items[0].Visible := CheckBox1.Checked
end;

procedure TForm1.Button1Click(Sender: PObj);
var SubMenu: PMenu;
   i: Integer;
begin
 SubMenu := NewMenu( nil, 100, [], nil );
 for i := 0 to 3 do
 begin
   SubMenu.Insert(-1, PChar("Test " + int2str(i)), nil, []);
 end;
 for i:=0 to P.Count-1 do
   if p.Items[i].Enabled =false then p.Items[i].visible:=true;
 P.InsertSubMenu(SubMenu, 4);
 for i:=0 to P.Count-1 do
   if p.Items[i].Enabled =false then p.Items[i].visible:=false;
SubMenu.Caption := "Sub Menu";
end;
[/CODE]

The cause seems to do with MF_BYPOSITION rather than MF_BYCOMMAND??


 
ECM ©   (2005-05-12 13:34) [1]

type
 PMenuAccess = ^TMenuAccess;
 TMenuAccess = object(TMenu)
 end;

procedure TForm1.Button1Click(Sender: PObj);
var SubMenu: PMenu;
   i: Integer;
begin
 SubMenu := NewMenu( nil, 100, [], nil );
 PMenuAccess(SubMenu).FCaption := "Sub Menu";

 for i := 0 to 4 do
 begin
   SubMenu.Insert(-1, PChar("Test " + int2str(i)), nil, []);
 end;

 P.InsertSubMenu(SubMenu, 4);
//  SubMenu.Caption := "Sub Menu";
end;


 
ECM ©   (2005-05-12 13:38) [2]

2 Kladov: Может есть смысл добавить Caption в параметры NewMenu?


 
ECM ©   (2005-05-12 13:48) [3]

Как вариант решения можно поправить в KOL.PAS:

//[procedure TMenu.SetMenuItemCaption]
procedure TMenu.SetMenuItemCaption( const Value: String );
var MII: TMenuItemInfo;
begin
 FCaption := Value;
 if fParent = nil then Exit; {+ecm}
{AK}if not (WinVer in [wv95,wvNT]) then
{AK}  MII.fMask := $40 {MIIM_STRING}
{AK}else begin
 MII.fMask := MIIM_TYPE;
 MII.fType := MFT_STRING;
{AK}end;
 //+++++++++++++++++++ to fix turning radio mark to check mark in NT4
 MII.cch := 0;
 GetInfo( MII );
 //------------------------------------------------------------------
 MII.dwTypeData := PChar( Value );
 MII.cch := Length( Value );
 SetInfo( MII );
end;


 
ECM ©   (2005-05-12 13:53) [4]

Забыл главное ...:)
после внесения исправления [3] код для Demo должен выглядеть так:

procedure TForm1.Button1Click(Sender: PObj);
var SubMenu: PMenu;
   i: Integer;
begin
 SubMenu := NewMenu( nil, 100, [], nil );

 for i := 0 to 4 do
 begin
   SubMenu.Insert(-1, PChar("Test " + int2str(i)), nil, []);
 end;

 SubMenu.Caption := "Sub Menu";  
 P.InsertSubMenu(SubMenu, 4);
end;


 
rofl   (2005-05-12 14:58) [5]

if u " re bugfixing, take also a look on the widechartostring function in the kol system.pas (of delphi 5)
it gives back 4 or 5 additional nonsense characters
like this

var s: string;
begin
 s:="b" + #0 + "l" + #0 + "a" + #0;
 memo1.add(widechartostring(@s[1]));
end;


 
thaddy   (2005-05-12 16:22) [6]

No, A wide string should end with #00#00



Страницы: 1 вся ветка

Текущий архив: 2006.01.01;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.043 c
14-1133650015
Piter
2005-12-04 01:46
2006.01.01
Проблема с Miranda


6-1126594397
VS
2005-09-13 10:53
2006.01.01
Интернетпочта


14-1133779473
k2
2005-12-05 13:44
2006.01.01
Математика для детей.


8-1122266318
Sankez
2005-07-25 08:38
2006.01.01
Как можно проиграть avi на рабочем столе ?


2-1133969354
ZeFiR
2005-12-07 18:29
2006.01.01
Как справиться с ошибкой Stack Overflow?