Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2007
    Location
    Delphi II
    Posts
    1,534

    Wink Yet Another Work-around by Centauri Soldier

    Hey fellas,

    ever get tired of sifting through millions of lines of code in your On Menu section. No worries here's the trick.

    Code:
    --this table creates your menu responses--best if it's in your globals and menu items can be in any order
    tAFMenuItem = {};
    tAFMenuItem[1] = {};
    tAFMenuItem[1].Text = "&Exit";
    tAFMenuItem[1].Code = [[
    Application.Exit(0);
    ]]
    tAFMenuItem[1].ID = 199; --this can be set to nil if you dont need a menu ID identifier. Use for duplicate Menu Item Names
    
    --Put this table on startup somewhere
    tAFMenuButtonProp = {};
    tAFMenuButtonProp.Width = 1;
    tAFMenuButtonProp.Height = 1;
    tAFMenuButtonProp.Visible = false;
    
    --put this function in your globals
    --======================>>>>>>>>>>>>>>>>>>>>>>>>>>>
    function Application.ClickMenu(tAFMenuTable) --[[>>
    <<                                               >>
    <<                                               >>
    <<<<<<<<<<<<<<<<<<<<<==========================--]]
    for nAFMenuIndex = 1, Table.Count(tAFMenuItem) do
    
    	if tAFMenuItem[nAFMenuIndex].ID then
    	
    		if tAFMenuTable.Text == tAFMenuItem[nAFMenuIndex].Text and tAFMenuTable.ID == tAFMenuItem[nAFMenuIndex].ID then
    		Page.CreateObject(OBJECT_BUTTON, "btn AF menu code", tAFMenuButtonProp);
    		Page.SetObjectScript("btn AF menu code", "On Click", tAFMenuItem[nAFMenuIndex].Code);
    		Page.ClickObject("btn AF menu code");
    		Page.CreateObject(OBJECT_BUTTON, "btn AF menu code", tAFMenuButtonProp);
    		break;
    		end
    		
    	else
    	
    		if tAFMenuTable.Text == tAFMenuItem[nAFMenuIndex].Text then
    		Page.CreateObject(OBJECT_BUTTON, "btn AF menu code", tAFMenuButtonProp);
    		Page.SetObjectScript("btn AF menu code", "On Click", tAFMenuItem[nAFMenuIndex].Code);
    		Page.ClickObject("btn AF menu code");
    		Page.CreateObject(OBJECT_BUTTON, "btn AF menu code", tAFMenuButtonProp);
    		break;
    		end
    		
    	end
    	
    end
    -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    end--|||||||||||||END FUNCTION|||||||||||||||||
    -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    
    --call the function in your On Menu section
    Application.ClickMenu(e_ItemInfo);
    Please let me know if you find a bug,
    Enjoy!

    ~CS
    Last edited by Centauri Soldier; 12-05-2008 at 09:37 AM.

  2. #2
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    But doesn't that mean I end up with more lines of code, except they are now in my Globals which is worse because Globals usually already has 1000's of lines of code. You have to do this for every menu item.
    Code:
    tAFMenuItem = {};
    tAFMenuItem[1] = {};
    tAFMenuItem[1].Text = "&Exit";
    tAFMenuItem[1].Code = [[
    Application.Exit(0);
    ]]
    tAFMenuItem[1].ID = 199; --this can be set to nil if you dont need a menu ID identifier. Use for duplicate Menu Item Names
    Instead of just this.
    Code:
    if e_ID == 199 then
    	Application.Exit(0);
    end
    It just makes no sense to create a button and put the code in the button and then call the button click when you can just call the code from the menu. Maybe I am not getting it but it seems like more work to me and I would rather have all my menu code in the On Menu section instead of cluttering up my Globals.
    Dermot

    I am so out of here

  3. #3
    Join Date
    Jun 2007
    Location
    Delphi II
    Posts
    1,534
    Hi Dermot,
    But doesn't that mean I end up with more lines of code, except they are now in my Globals...
    If all you have for your menu code is a couple if lines then this function is not for you. This is for projects (like the one for which I built this) that require hundreds of lines of code for the menu. It is easier to find my section when they are in this table and easier to edit them.

    Also, I don't need to worry about the menu IDs (as long as there are no duplicate names, in which case I can put the id into the tAFMenuITem[index].ID table), I can simply list the menu text and then type the code.

    As far as your example with the one line of code, you are correct...this would be a complete waste of time. But for those huge projects it works great.

    Also, I store all my added functions (such as this one) in a script folder and call them all on start up with a single command line. So for me, the function is not listed in my globals but in a lua file. As far as the table, you can put this anywhere before you call the Application.ClickMenu() function.

    I have another function for the table called Application.MenuEdit(). I Put Application.MenuEdit("Exit",[[Application.Exit();]],nil); and the function does the rest. It dynamically adds code to the menu.

    Of course this works well with my other function that builds the menu for me too. This is my attempt to shorten the time needed to code a thing. Menus have always been my bane so when I see a chance to strike a blow against them for all sane coders out there I do so. Alas, at some point I'm sure your signature statement will apply to my efforts.
    Last edited by Centauri Soldier; 12-05-2008 at 12:57 PM.

  4. #4
    Join Date
    Oct 2007
    Location
    Gensokyo
    Posts
    1,324
    Quote Originally Posted by Centauri Soldier View Post
    Application.MenuEdit("Exit",[[Application.Exit();]],nil);
    You don't need to say nil, If you don't specify it. It would be nil.

  5. #5
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    I was referring to apps with a lot of menu items. My example was just to show that the normal way takes 3 lines of code per menu item but yours takes 6 lines. Your solution means more lines of code per menu item because of having to build the table. Also if you edit the text of a menu item, you have to edit the table also.

    But if you find it easier then go for it. I just have a very hard time seeing how it makes things easier.
    Dermot

    I am so out of here

  6. #6
    Join Date
    Jun 2007
    Location
    Delphi II
    Posts
    1,534
    Quote Originally Posted by ShadowUK View Post
    You don't need to say nil, If you don't specify it. It would be nil.
    True, I just put it in there to be pedantic (or thorough if you prefer that word ).

    Here Dermot, try these (no more tables). Just call them all on start up (run script file) and you will see the beauty of the code. Obviously, I have much to do to this code as far as adding more functions but these ones in the rar file are finished and bug tested with no errors (so far ). You should be able to use Menu.AddCode pretty much anywhere but the Menu.Click has to be in the On Menu section with e_ItemInfo as the function's table. This is how it should look. Menu.Click(e_ItemInfo);

    Also if you edit the text of a menu item, you have to edit the table also.
    Well, you have to do this in any case. But in the case of these tables, there is no specific order required.

    Let me know what you think of this approach.
    Attached Files
    Last edited by Centauri Soldier; 12-05-2008 at 02:10 PM.

Similar Threads

  1. ANSI To UNICODE Is Finished!
    By coderanger in forum AutoPlay Media Studio 6.0
    Replies: 7
    Last Post: 08-13-2007, 09:27 AM
  2. Any one can let me know if this work with AMS
    By DaSoul in forum AutoPlay Media Studio 6.0
    Replies: 2
    Last Post: 06-23-2007, 09:21 PM
  3. Does Autorun MAX Work on Macs?
    By Adam in forum Autorun MAX! 2.1 FAQ
    Replies: 0
    Last Post: 08-29-2006, 12:50 PM
  4. Having problems getting installer frontend to work
    By Scott Lawrence in forum AutoPlay Media Studio 5.0
    Replies: 2
    Last Post: 07-24-2006, 03:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts