View Full Version : Example - Function that deletes all Objects on Page!
Intrigued
04-22-2006, 09:18 AM
--This is a function that will allow for the deletion of all Objects on a page.
function f_DeleteAllObjects()
-- Get a table listing of all the Objects (if there are any)
tblObjects = Page.EnumerateObjects()
-- Continue on only if there is at least one Object
if tblObjects ~= nil then
for i,v in tblObjects do
Page.DeleteObject(v)
end
end
end
-- "Call" (to use) the function
f_DeleteAllObjects()
Here's a function that will list all the objects in a page
function ListAllObjects()
Objects = Page.EnumerateObjects()
if Objects ~= nil then
for i,v in Objects do
v2 = Page.GetObjectType(v);
if v2 == 0 then
j = "Button"
elseif v2 == 1 then
j = "Label"
elseif v2 == 2 then
j = "Paragraph"
elseif v2 == 3 then
j = "Image"
elseif v2 == 4 then
j = "Flash"
elseif v2 == 5 then
j = "Video"
elseif v2 == 6 then
j = "Web"
elseif v2 == 7 then
j = "Input"
elseif v2 == 8 then
j = "Hotspot"
elseif v2 == 9 then
j = "Listbox"
elseif v2 == 10 then
j = "Combobox"
elseif v2 == 11 then
j = "Progress"
elseif v2 == 12 then
j = "Tree"
elseif v2 == 40 then
j = "Plugin"
end
ListBox.AddItem("ListBox1", v.." ("..j..")", "");
end
end
end
-- calling the function
ListAllObjects()
Intrigued
04-27-2006, 07:23 PM
Alight right then!
:yes
Roboblue
04-28-2006, 03:13 PM
WOW, I'm still having problems adding objects and here's Intrique creating a function to delete objects.
Both of the above has been stored, thanx guys.
Intrigued
04-28-2006, 06:17 PM
WOW, I'm still having problems adding objects and here's Intrique creating a function to delete objects.
Both of the above has been stored, thanx guys.
NP Roboblue, just keep the "Army of One" learning and excelling and we'll keep the suggestions pumping out.
;)
Daniel TM
05-01-2006, 01:28 AM
That function was very easy to make. Before I got in this thread I already imagined exactly how the code would look like because of the title. Speaking in objects...
Here's a function that copies properties from one object to another:
You can copy the properties from an input object to another input object.
You can also copy the properties from an input object to a listbox object. The properties are set with no problems, just the unique properties aren't set.
If you provide a plugin object in any argument then -1 is returned.
If the last error is diferent from 0 then nil is returned.
If you don't provide a plugin object in any argument and the last error is equal to 0 then the properties are copied succesfully and a table containing the type and the properties of both objects is returned.
--[[
Author: Daniel TM
Function: CopyObjectProperties
Purpose: Copies the properties of one object to another.
Arguments: (string) From - The object's properties to copy.
(string) To - The object to copy the properties to.
Returns: (table) A table containing the type and the properties of the objects.
FromProperties - The properties of the object you copied the properties from.
FromType - The type of object you copied the properties from.
ToProperties - The old properties of the object you copied the properties to.
ToType - The type of object you copied the properties to.
If the user provides a plugin object then nil is returned.
Example: CopyObjectProperties("From", "To");
]]--
function CopyObjectProperties(From, To)
FromType = Page.GetObjectType(From);
ToType = Page.GetObjectType(To);
if FromType == OBJECT_PLUGIN or ToType == OBJECT_PLUGIN then
return -1;
elseif Application.GetLastError() ~= 0 then
return nil
elseif FromType ~= OBJECT_PLUGIN and ToType ~= OBJECT_PLUGIN and Application.GetLastError() ~= 0 then
if FromType == OBJECT_BUTTON then
FromProperties = Button.GetProperties(From);
elseif FromType == OBJECT_LABEL then
FromProperties = Label.GetProperties(From);
elseif FromType == OBJECT_PARAGRAPH then
FromProperties = Paragraph.GetProperties(From);
elseif FromType == OBJECT_IMAGE then
FromProperties = Image.GetProperties(From);
elseif FromType == OBJECT_FLASH then
FromProperties = Flash.GetProperties(From);
elseif FromType == OBJECT_VIDEO then
FromProperties = Video.GetProperties(From);
elseif FromType == OBJECT_WEB then
FromProperties = Web.GetProperties(From);
elseif FromType == OBJECT_INPUT then
FromProperties = Input.GetProperties(From);
elseif FromType == OBJECT_HOTSPOT then
FromProperties = Hotspot.GetProperties(From);
elseif FromType == OBJECT_LISTBOX then
FromProperties = ListBox.GetProperties(From);
elseif FromType == OBJECT_COMBOBOX then
FromProperties = ComboBox.GetProperties(From);
elseif FromType == OBJECT_PROGRESS then
FromProperties = Progress.GetProperties(From);
elseif FromType == OBJECT_TREE then
FromProperties = Tree.GetProperties(From);
end
if ToType == OBJECT_BUTTON then
ToProperties = Button.GetProperties(To);
elseif FromType == OBJECT_LABEL then
ToProperties = Label.GetProperties(To);
elseif FromType == OBJECT_PARAGRAPH then
ToProperties = Paragraph.GetProperties(To);
elseif FromType == OBJECT_IMAGE then
ToProperties = Image.GetProperties(To);
elseif FromType == OBJECT_FLASH then
ToProperties = Flash.GetProperties(To);
elseif FromType == OBJECT_VIDEO then
ToProperties = Video.GetProperties(To);
elseif FromType == OBJECT_WEB then
ToProperties = Web.GetProperties(To);
elseif FromType == OBJECT_INPUT then
ToProperties = Input.GetProperties(To);
elseif FromType == OBJECT_HOTSPOT then
ToProperties = Hotspot.GetProperties(To);
elseif FromType == OBJECT_LISTBOX then
ToProperties = ListBox.GetProperties(To);
elseif FromType == OBJECT_COMBOBOX then
ToProperties = ComboBox.GetProperties(To);
elseif FromType == OBJECT_PROGRESS then
ToProperties = Progress.GetProperties(To);
elseif FromType == OBJECT_TREE then
ToProperties = Tree.GetProperties(To);
end
if ToType == OBJECT_BUTTON then
Button.SetProperties(To, FromProperties);
elseif ToType == OBJECT_LABEL then
Label.SetProperties(To, FromProperties);
elseif ToType == OBJECT_PARAGRAPH then
Paragraph.SetProperties(To, FromProperties);
elseif ToType == OBJECT_IMAGE then
Image.SetProperties(To, FromProperties);
elseif ToType == OBJECT_FLASH then
Flash.SetProperties(To, FromProperties);
elseif ToType == OBJECT_VIDEO then
Video.SetProperties(To, FromProperties);
elseif ToType == OBJECT_WEB then
Web.SetProperties(To, FromProperties);
elseif ToType == OBJECT_INPUT then
Input.SetProperties(To, FromProperties);
elseif ToType == OBJECT_HOTSPOT then
Hotspot.SetProperties(To, FromProperties);
elseif ToType == OBJECT_LISTBOX then
ListBox.SetProperties(To, FromProperties);
elseif ToType == OBJECT_COMBOBOX then
ComboBox.SetProperties(To, FromProperties);
elseif ToType == OBJECT_PROGRESS then
Progress.SetProperties(To, FromProperties);
elseif ToType == OBJECT_TREE then
Tree.SetProperties(To, FromProperties);
end
ReturnValue = {};
ReturnValue.FromProperties = FromProperties;
ReturnValue.FromType = FromType;
ReturnValue.ToProperties = ToProperties;
ReturnValue.ToType = ToType;
return ReturnValue;
end end
Enjoy :yes
Daniel TM
05-01-2006, 01:48 AM
Guys, I made changes to the function and I forgot to update the comment you find in the begining of the function. The comment at the begining of the function says that CopyObjectProperties returns something that it doesn't. Here's the updated comment:
--[[
Author: Daniel TM
Function: CopyObjectProperties
Purpose: Copies the properties of one object to another.
Arguments: (string) From - The object's properties to copy.
(string) To - The object to copy the properties to.
Returns: (table) A table containing the type and the properties of the objects.
FromProperties - The properties of the object you copied the properties from.
FromType - The type of object you copied the properties from.
ToProperties - The old properties of the object you copied the properties to.
ToType - The type of object you copied the properties to.
If the user provides a plugin object then -1 is returned.
If an error occures then nil is returned.
Example: CopyObjectProperties("From", "To");
]]--
yosik
05-01-2006, 10:08 AM
Good one, Daniel.
I am sure it willome handy.
Thanks
Yossi
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.