Difference between revisions of "Lua:getPropertyList"

From Cheat Engine
Jump to navigation Jump to search
(Created page with "getPropertyList(class) : Returns a stringlist object containing all the published properties of the specified class (free the list when done) (Note, not all classed with prope...")
 
(Major overhaul of the post.)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
getPropertyList(class) : Returns a stringlist object containing all the published properties of the specified class (free the list when done) (Note, not all classed with properties have 'published' properties. E.g: stringlist)
+
[[Category:Lua]]
 +
{{CodeBox|'''function''' getPropertyList(''class'') ''':''' StringList}}
  
<pre>
+
Returns a [[Lua:Class:Stringlist|StringList]] object containing all published properties of the specified class.
r = getPropertyList(getInternet())
 
  
for i=0, r.Count-1, 1 do
+
The returned list must be freed when it is no longer needed.
   print( r[i] )
+
 
 +
Not every class with properties exposes them as published properties. For example, some classes may have usable properties that do not appear in the returned list.
 +
 
 +
===Function Parameters===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Parameter
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|class
 +
|Object / Class
 +
|The class or object whose published properties should be listed.
 +
|}
 +
 
 +
===Returns===
 +
[[Lua:Class:Stringlist|StringList]] — A list containing the published property names of the specified class.
 +
 
 +
===Examples===
 +
 
 +
====Get published properties of the main form====
 +
<syntaxhighlight lang="lua" line highlight="2">
 +
local form = getMainForm()
 +
local properties = getPropertyList(form)
 +
 
 +
for i = 0, properties.Count - 1 do
 +
  print(properties[i])
 +
end
 +
 
 +
properties.destroy()
 +
</syntaxhighlight>
 +
 
 +
====Check whether a property exists====
 +
<syntaxhighlight lang="lua" line highlight="2">
 +
local form = getMainForm()
 +
local properties = getPropertyList(form)
 +
 
 +
local hasCaption = false
 +
 
 +
for i = 0, properties.Count - 1 do
 +
  if properties[i] == "Caption" then
 +
    hasCaption = true
 +
    break
 +
  end
 +
end
 +
 
 +
print("Has Caption: " .. tostring(hasCaption))
 +
 
 +
properties.destroy()
 +
</syntaxhighlight>
 +
 
 +
====List properties of a created control====
 +
<syntaxhighlight lang="lua" line highlight="3">
 +
local form = createForm(false)
 +
local button = createButton(form)
 +
local properties = getPropertyList(button)
 +
 
 +
for i = 0, properties.Count - 1 do
 +
  print(properties[i])
 +
end
 +
 
 +
properties.destroy()
 +
form.destroy()
 +
</syntaxhighlight>
 +
 
 +
====Use pcall to ensure the list is destroyed====
 +
<syntaxhighlight lang="lua" line highlight="2">
 +
local form = getMainForm()
 +
local properties = getPropertyList(form)
 +
 
 +
local ok, err = pcall(function()
 +
  for i = 0, properties.Count - 1 do
 +
    print(properties[i])
 +
  end
 +
end)
 +
 
 +
properties.destroy()
 +
 
 +
if not ok then
 +
   print(err)
 +
end
 +
</syntaxhighlight>
 +
 
 +
====Handle classes without published properties====
 +
<syntaxhighlight lang="lua" line highlight="2">
 +
local list = createStringlist()
 +
local properties = getPropertyList(list)
 +
 
 +
if properties.Count == 0 then
 +
  print("No published properties found")
 +
else
 +
  for i = 0, properties.Count - 1 do
 +
    print(properties[i])
 +
  end
 +
end
 +
 
 +
properties.destroy()
 +
list.destroy()
 +
</syntaxhighlight>
 +
 
 +
====Copy property names into another StringList====
 +
<syntaxhighlight lang="lua" line highlight="2">
 +
local form = getMainForm()
 +
local properties = getPropertyList(form)
 +
local copy = createStringlist()
 +
 
 +
for i = 0, properties.Count - 1 do
 +
  copy.add(properties[i])
 
end
 
end
</pre>
+
 
 +
print("Copied properties: " .. tostring(copy.Count))
 +
 
 +
copy.destroy()
 +
properties.destroy()
 +
</syntaxhighlight>
 +
 
 +
{{LuaSeeAlso}}

Latest revision as of 00:23, 27 June 2026

<> Lua API Reference

function getPropertyList(class) : StringList

Returns a StringList object containing all published properties of the specified class.

The returned list must be freed when it is no longer needed.

Not every class with properties exposes them as published properties. For example, some classes may have usable properties that do not appear in the returned list.

Function Parameters[edit]

Parameter Type Description
class Object / Class The class or object whose published properties should be listed.

Returns[edit]

StringList — A list containing the published property names of the specified class.

Examples[edit]

Get published properties of the main form[edit]

1 local form = getMainForm()
2 local properties = getPropertyList(form)
3 
4 for i = 0, properties.Count - 1 do
5   print(properties[i])
6 end
7 
8 properties.destroy()

Check whether a property exists[edit]

 1 local form = getMainForm()
 2 local properties = getPropertyList(form)
 3 
 4 local hasCaption = false
 5 
 6 for i = 0, properties.Count - 1 do
 7   if properties[i] == "Caption" then
 8     hasCaption = true
 9     break
10   end
11 end
12 
13 print("Has Caption: " .. tostring(hasCaption))
14 
15 properties.destroy()

List properties of a created control[edit]

 1 local form = createForm(false)
 2 local button = createButton(form)
 3 local properties = getPropertyList(button)
 4 
 5 for i = 0, properties.Count - 1 do
 6   print(properties[i])
 7 end
 8 
 9 properties.destroy()
10 form.destroy()

Use pcall to ensure the list is destroyed[edit]

 1 local form = getMainForm()
 2 local properties = getPropertyList(form)
 3 
 4 local ok, err = pcall(function()
 5   for i = 0, properties.Count - 1 do
 6     print(properties[i])
 7   end
 8 end)
 9 
10 properties.destroy()
11 
12 if not ok then
13   print(err)
14 end

Handle classes without published properties[edit]

 1 local list = createStringlist()
 2 local properties = getPropertyList(list)
 3 
 4 if properties.Count == 0 then
 5   print("No published properties found")
 6 else
 7   for i = 0, properties.Count - 1 do
 8     print(properties[i])
 9   end
10 end
11 
12 properties.destroy()
13 list.destroy()

Copy property names into another StringList[edit]

 1 local form = getMainForm()
 2 local properties = getPropertyList(form)
 3 local copy = createStringlist()
 4 
 5 for i = 0, properties.Count - 1 do
 6   copy.add(properties[i])
 7 end
 8 
 9 print("Copied properties: " .. tostring(copy.Count))
10 
11 copy.destroy()
12 properties.destroy()

Main Pages

Core Lua documentation entry points

Lua
Script Engine