Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "KOL";
Текущий архив: 2006.01.01;
Скачать: [xml.tar.bz2];

Вниз

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 вся ветка

Форум: "KOL";
Текущий архив: 2006.01.01;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.01 c
2-1134727704
Goast
2005-12-16 13:08
2006.01.01
Проблема с CoolTrayIcon


2-1134464872
orsson
2005-12-13 12:07
2006.01.01
Помогите кто чем может


14-1134305309
AllWeyt
2005-12-11 15:48
2006.01.01
Проекты


14-1134020215
baks_uz
2005-12-08 08:36
2006.01.01
MiTeC System Information Component


14-1133840469
аРТ
2005-12-06 06:41
2006.01.01
Заберите меня на другую работу!! ААААААААААаааааааа





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский