PDA

View Full Version : This doesn't make any sense...



T3STY
02-27-2010, 01:53 PM
As in thread's title, this is just a nonsense thing... in a project I have this function on my Global functions event:


function CreateButtons()
WinSize = Window.GetSize(Application.GetWndHandle());

for i, sButton in tblButtons do
tblNewButton = {};
TipoPulsante = INIFile.GetValue(ButtonsINI, sButton, "TipoPulsante");
PosizioneX = INIFile.GetValue(ButtonsINI, sButton, "PosizioneX");
tblNewButton.Width = tblTema.DimXButNormale;
tblNewButton.Height = tblTema.DimYButNormale;
if (PosizioneX == "$Middle") then
PosizioneX = ((WinSize.Width - 200) / 2 + 200);
else
PosizioneX = String.ToNumber(PosizioneX);
end

tblNewButton.ButtonFile = tblTema.ButNormale;
tblNewButton.Text = INIFile.GetValue(ButtonsINI, sButton, "Nome");
tblNewButton.FontName = tblTema.FontTexButNormale;
tblNewButton.FontSize = String.ToNumber(tblTema.DimTexButNormale);
tblNewButton.FontWeight = tblTema.BoldTexButNormale;
tblNewButton.ColorNormal = Math.HexColorToNumber(tblTema.ColTexButNormaleNorm ale);
tblNewButton.ColorHighlight = Math.HexColorToNumber(tblTema.ColTexButNormaleAcce so);
tblNewButton.ColorDown = Math.HexColorToNumber(tblTema.ColTexButNormaleClic cato);
tblNewButton.ColorDisabled = Math.HexColorToNumber(tblTema.ColTexButNormaleDisa bilitato);
tblNewButton.TooltipText = INIFile.GetValue(ButtonsINI, sButton, "TestoPopUp");
tblNewButton.Alignment = ALIGN_CENTER;
tblNewButton.HighlightSound = SND_NONE;
tblNewButton.ClickSound = SND_NONE;
tblNewButton.X = PosizioneX;
tblNewButton.Y = String.ToNumber(INIFile.GetValue(ButtonsINI, sButton, "PosizioneY"));
tblNewButton.Enabled = true;
tblNewButton.Cursor = CURSOR_HAND;
if (TipoPulsante == "1") then
tblNewButton.Style = BTNSTYLE_TOGGLE;
--> here tblNewButton.ToggleState = BTN_TOGGLE_UP;
--tblNewButton.ToggleState = BTN_UP;
elseif (TipoPulsante == "2") then
tblNewButton.Style = BTNSTYLE_TOGGLE;
--> here tblNewButton.ToggleState = BTN_TOGGLE_DOWN;
--tblNewButton.ToggleState = BTN_DOWN;
elseif (TipoPulsante == "0") then
tblNewButton.Style = BTNSTYLE_STANDARD;
tblNewButton.Cursor = CURSOR_ARROW;
end

Page.CreateObject(OBJECT_BUTTON, sButton, tblNewButton);

--> here if (TipoPulsante == 0) then
Width = (WinSize.Width - 200);
Button.SetEnabled(sButton, false);
Button.SetSize(sButton, Width, tblTema.DimYButNormale);
end

end
end


where you can read "here" there are the problems. So, what's the problem ?
When I call this function anything goes well while creating buttons, but:
-the toggle state is not set with the BTN_TOGGLE_UP/DOWN;
--this can be "fixed" by using BTN_UP/DOWN wich are the Button.SetState values.. WTH ??!

-I used a for..do function because I have to create lots of buttons with different properties.But there are buttons I need to be enabled, and buttons I need to be Disabled. Here we have another problem because if I set in the table the button as disabled, the first button in the list is set as disabled with it's disabled state image, but the next others are set as disabled with the normal state image. I solved by adding another if after creating thew button (3rd "here" in the code) but I don't like it like this.

Can anyone explain me why are those things happening and how can I fix this ?

p.s. Inthe table I've used also some variables from another table, called tblTema - an associative table, in the project wich is too long, almost unuseful for you. If you need it just ask.

p.p.s. Don't think about the language.. in my projects I'm used to use both English and Italian languages... :D

EDIT
I was forgetting!
When using BTN_UP/DOWN the buttons are set correctly in thge application but when the cursor enters application's window the buttons don't maintain their up/down state, they're state becomes UP for enabled buttons and disabled buttons remains as they're. What is this ? Do you think my AMS is having some issues ??

T3STY
02-27-2010, 02:33 PM
Just reinstalled AMS and nothing changes..
EDIT
I've tried to put directly BTN_DOWN in the table (so, for all buttons) but they don't even maintain the state whe cursor enters application's window...

T3STY
02-27-2010, 03:21 PM
Third post in half an hour .. I think IR's staff will ban me out next time I post here.. :D

Anyhow, I post this time just to ask you a simple thing, and to have some answers from you.
In an application, create a function (on the Global Functions) wich creates a button using Page.CreateObject(), and the default button properties table (by doing right click > quick scripts > button properties table). You have just to add a path for a button file and set the button as TOGGLE with toggle state as BTN_TOGGLE_DOWN. Then, on the OnShow event call the function created before.
-When you run the application is the button being created as expected ?
-The Down state (BTN_TOGGLE_DOWN) is working ? if is not working, try with BTN_DOWN.
-When cursor enters application's window, does the button created maintain the down state ? and with BTN_DOWN ?

I did this but in my application the answers are: 1) no; 2) no/yes; 3) no/no.

Please guys, I really don't know what I have to do to fix those problems and I really need a solution.

Centauri Soldier
02-27-2010, 03:27 PM
Are you firing the function in the OnPreload event? If so, you may not be able to manipulate certain aspects of the button properties. I've found that the success of altering objects OnPreload is sketchy at best.

T3STY
02-27-2010, 03:31 PM
The OnPreload event will not create the button as the window is not created at the OnPreload event runtime. So, you have to call the function on the OnShow event, as i did.

T3STY
03-01-2010, 03:55 PM
So no solutions ? Couldn't that be just another bug in AMS ? Or just a bug in My AMS...

RizlaUK
03-01-2010, 04:51 PM
agreed, its a bug :yes, i just ran some tests and i have smae resluts

T3STY
03-02-2010, 04:01 PM
And I have found the solution, or just part of it...
When you create the button, create the properties table with values you want. They'll not be applied like they should when using Page.CreateObject(), so just use the same table to set the button properties with Button.SetProperties().

This worked for me, hope it's helpful for you. And, IR, please fix this bug in AMS 8 :)

RizlaUK
03-02-2010, 04:19 PM
i dont often create objects on the fly, but its something to bear in mind for when i do :yes

T3STY
03-02-2010, 06:44 PM
Another bug, I think it depends on the before bug.
I tried to make a verbose button creation, and after each property I set a Debug.Print() function to see each value how really it's.
When the application arrives at the Enabled and ToggleState values an error dialog appears with:

for Enabled:
On Show, Line 628: attemp to concatenate field 'Enabled' (a boolean value)

for ToggleState:
On Show, Line 630: attemp to concatenate field 'ToggleState' (a nil value)

even if my values are:
tblBtnProps.Enabled = true;
tblBtnProps.ToggleState = BTNTOGGLE_UP;

And I think is because of Enabled that buttons don't disable with correct button image; and it's because of ToggleState that application don't maintain buttons state when cursor enter application's window.
Now, for who needs a workaround, when creating button don't set those two values in the table. If you need to Enable/Disable a button or set it's state do it later with Button.SetEnabled() and Button.SetState().

I hope also this will be useful for someone ;)

RizlaUK
03-03-2010, 02:56 AM
for Enabled:
On Show, Line 628: attemp to concatenate field 'Enabled' (a boolean value)

^^ thats because 'Enabled' is a boolean, you can not print a boolean value directly, use 'tostring()' function to convert the boolean value into a text value, this one is NOT a bug

EG:

Enabled=true
Debug.Print(tostring(Enabled);

Enabled=false
Debug.Print(tostring(Enabled);


for ToggleState:
On Show, Line 630: attemp to concatenate field 'ToggleState' (a nil value)

'BTNTOGGLE_UP' should be 'BTN_TOGGLE_UP'

try like this and see what happens

tblBtnProps.Enabled = true;
tblBtnProps.ToggleState = 1--1 for down or 0 for up

T3STY
03-03-2010, 06:36 AM
no, ToggleState is just "broken", I used BTNTOGGLE_UP/DOWN because this is the default value type the table has and also because in the help files is shown like this. Anyhow, tried with 0, 1 and nothing, it's still having a nil value error:
http://img193.imageshack.us/img193/717/senzanomeoq.th.png (http://img193.imageshack.us/img193/717/senzanomeoq.png)

I didn't knew boolean values cannot be printed normally.. sorry for that.

RizlaUK
03-03-2010, 08:38 AM
yeah,. i agree in that case, post it in the bugs forum with a link to this thread to get IR's attention


for the short term, make your own create button function that sets the props


function CreateButton(sName, tProps)
Page.CreateObject(OBJECT_BUTTON, sName, tProps);
-- Test for error
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
Button.SetProperties(sName, tProps);
end
end

T3STY
03-03-2010, 11:37 AM
Just posted in the other section.

The function you posted, that was my solution since I've found where's the problem. Thanks for suggestion anyway :)