Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Get form component names from other form

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu Oct 15, 2020 11:52 pm    Post subject: Get form component names from other form Reply with quote

How?.

Let say:
1. Form1 created using form designer/Lua with some components.
2. Form1 save as CT file
3, Form2, which created using Lua script and save as a Lua file and add as Table File on form1.CT
4. There are a function to call form2 from form1 using readStringLocal and loadString.
5. On form2 there are a function to listing form1 component names, but this function return error since form1 name return as nil value.

To list all components name on a form, I use:

Code:
for i = 0, formName.ComponentCount - 1 do
     local compName = formName.Component[i].Name
     print(compName)
end

--- this is work if call from form1.CT


But not work if call from form2.

So, how to get form1 components names call from form2?

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25814
Location: The netherlands

PostPosted: Fri Oct 16, 2020 1:13 am    Post subject: Reply with quote

look into components recursively as well
if you encounter a component check out it's own components as well

the way you create objects also affects this

if you create a control on a panel using
Code:

control=createButton(form.panel)

it won't be found on the form and only on the panel level

vut if you do
Code:

control=createButton(form)
control.Parent=form.panel

it will be found on the form level

(formdesigner creates on the form level)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Oct 16, 2020 4:34 am    Post subject: Reply with quote

Thanks DB for the details, I try it and find if components name and set parent for the components is important in case to initialize the components and their owner; which usually ignored by trainer creator.

This example just work fine.

Code:
if f1 then f1.Destroy() end
if f2 then f2.Destroy() end

----- Create Parent Form
f1 = createForm()
f1.setPosition(400,200)

b1 = createButton(f1)
b1.Caption = 'Button1'
b1.Parent = f1
b1.Name = 'Button1'

l1 = createLabel(f1)
l1.Top = 100
l1.Caption = 'This is Label1 on Form 1'
l1.Parent = f1
l1.Name = 'Label1'

b1.OnClick = function()
 f2.Show()
end


----- Create Child Form
f2 = createForm()
f2.setPosition(400,400)

cb = createComboBox(f2)
cb.Parent = f2
cb.Name = 'Form2_ComboBox1'

b2 = createButton(f2)
b2.Left = 150
b2.Caption = 'Button2'
b2.Parent = f2
b2.Name = 'Form2_Button1'

b2.OnClick = function()
 for i = 0, f1.ComponentCount-1 do
  cb.Items.Add(f1.Component[i].Name)
 end
end

f2.Hide()


And also I try to adopt Delphi function to get a control parent.

Code:
function GetParentForm(Control, TopForm)
 TopForm = true
 while (TopForm or not Control == 'TCEForm')and (Control.Parent ~= nil) do
  Control = Control.Parent
  if Control == 'TCEForm' then
     Result = TCEForm(Control)
  else
     Result  = nil
  end
 end
end


_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites