Главная страница
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.039 c
1-1133516129
Igor_thief
2005-12-02 12:35
2006.01.01
Окно встроенное в окно


2-1134245842
Demon1313
2005-12-10 23:17
2006.01.01
Срочно плиз-как сделать чтоб при каждом запуске приложения в


1-1133630552
Задумавшийся
2005-12-03 20:22
2006.01.01
Хм. А как определить - Unicode, UTF-8 или ANSI?


1-1133634173
Дмитрий_05
2005-12-03 21:22
2006.01.01
Раскрытие PopupMenu на форме


4-1128249749
Энтри
2005-10-02 14:42
2006.01.01
wm_setcursor