Modify

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#758 closed Bug (No Bug)

ControlGetHandle() does not work if controlID is passed as string type variable

Reported by: shEiD Owned by:
Milestone: Component: AutoIt
Version: 3.3.0.0 Severity: None
Keywords: Cc:

Description

In my script, I get controlID variable from registry with RegRead(). RegRead() returns value as string, although it is a number.
After some confusing errors, I found, that ControlGetHandle("title", "text", controlID) function does not work, if you pass a string type variable for controlID.

In the example I simply set the controlID variable and change it to string and back to int:

#include <GuiToolBar.au3>
Opt("WinTitleMatchMode", 2)

$toolbar_id = 59392
$h_wnd = WinGetHandle($win_title)

; does not work
$toolbar_id = String($toolbar_id)
$h_toolbar = ControlGetHandle($h_wnd, "", $toolbar_id)
ConsoleWrite('$h_toolbar = ' & $h_toolbar & @CRLF)

; convert back to Int and it works!
$toolbar_id = Int($toolbar_id)
$h_toolbar = ControlGetHandle($h_wnd, "", $toolbar_id)
ConsoleWrite('$h_toolbar = ' & $h_toolbar & @CRLF)

The console output after running this code:
$h_toolbar =
$h_toolbar = 0x008908D6

Attachments (0)

Change History (2)

comment:1 Changed 16 years ago by Valik

  • Resolution set to No Bug
  • Status changed from new to closed

This is not a bug and the behavior is correct. Casting via Number() or Int() is the correct thing to do.

comment:2 Changed 16 years ago by Valik

Just to expand on my previous comment, it's not a bug. AutoIt only looks at "is the variable a number or is it a string". The contents of the string don't matter. This is the correct behavior because if it tried to treat all numeric strings as control ID's it would become impossible to find a control that had numeric text.

So once again, casting is the correct thing to do. Any time you read from a file, an INI file, the registry, user input via GUI or just about anywhere, you're probably going to need to cast the returned value via the Number() function because almost invariably it will be returned as a string.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.