Главная страница
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
14-1134215248
Dilly
2005-12-10 14:47
2006.01.01
Книга по делфи


4-1130585063
AllDontFire
2005-10-29 15:24
2006.01.01
Как получить адрес процедур собственной программы (по названию п)


2-1134633754
ZZZ
2005-12-15 11:02
2006.01.01
Код клавиши Del.


3-1131523537
mpokemonov
2005-11-09 11:05
2006.01.01
StoreProcedure+InterBase


2-1134542066
ALex_
2005-12-14 09:34
2006.01.01
Языки