Главная страница
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.024 c
1-1132811400
Pank83
2005-11-24 08:50
2006.01.01
taskbar


14-1134235288
Kerk
2005-12-10 20:21
2006.01.01
Весь день кодю на Прологе.


2-1134592806
Free0n
2005-12-14 23:40
2006.01.01
Помогите разобраться с файлами


2-1134640643
Uzver
2005-12-15 12:57
2006.01.01
Как открыть файл?


1-1133789961
Экспериментатор
2005-12-05 16:39
2006.01.01
Как в MDI приложении сделать чтобы MDI-child окно максимизировало