Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a non-existent object 1

Status
Not open for further replies.

kidmar

Programmer
Mar 2, 2006
17
0
0
IT
Hi,
In my program i can open a window typing its name in a box.
My problem is that if I write the name of a non-existent window the program crushes with the following error:
" Application terminated. Unknown object type...."
- Is there a way to know if the object exists in the pbl list?
- Is there a function to get the list of objects of a pbl?
Thank you,
Marco Conca.

Using PowerBuilder 9.01 build 7119
 
hi
see the PB's Help of Function "LibraryDirectory"
Here someone wrote a Function to list the objects in the pbl
eg:
//====================================================================
// Function: nvo_orca.of_listobjects()
//--------------------------------------------------------------------
// arguments:
// value string as_libname
// value libdirtype anum_objtype
// reference string as_objnames[]
// reference string as_times[]
// reference string as_comments[]
//--------------------------------------------------------------------
// return: integer
//--------------------------------------------------------------------
// Description:
//--------------------------------------------------------------------
// Author: Date: 2007.03.20
//--------------------------------------------------------------------
// CopyRight:
//--------------------------------------------------------------------
// History:
//
//
//====================================================================


string ls_objects, ls_line
long ll_pos1, ll_pos2, ll_tabpos1, ll_tabpos2, ll_index
string ls_objnames[], ls_times[], ls_comments[]

ls_objects = librarydirectory(as_libname, anum_objtype)
ll_pos1 = 1
ll_pos2 = pos(ls_objects, '~t~n', ll_pos1)
do while ll_pos2 > ll_pos1
ls_line = mid(ls_objects, ll_pos1, ll_pos2 - ll_pos1)
ll_tabpos1 = pos(ls_line, '~t')
ll_tabpos2 = pos(ls_line, '~t', ll_tabpos1 + 1)
ll_index ++
ls_objnames[ll_index] = left(ls_line, ll_tabpos1 - 1)
ls_times[ll_index] = mid(ls_line, ll_tabpos1 + 1, ll_tabpos2 - ll_tabpos1 - 1)
ls_comments[ll_index] = mid(ls_line, ll_tabpos2 + 1)
ll_pos1 = ll_pos2 + 2
ll_pos2 = pos(ls_objects, '~t~n', ll_pos1)
loop

as_objnames = ls_objnames
as_times = ls_times
as_comments = ls_comments

return ll_index
 
Can you put your Open( ) call in Try/Catch blocks? (I don't know that it would handle this error, but might be worth a try)
 
Look up the Handle function. If you try to get the handle of a nonexistent object it will probably return a 0.
 
I can't use the handle function because I don't have an "objectname" but a string as argument.

The Try/Catch block doesen't help me preventing the error (and I don't think it was made for that). Anyway I tried to use it:
w_data_sheet w_sheet1
try
OpenSheetWithParm(w_sheet1, '', 'w_prova', w_sheet1, 0, Original!)
finally
messagebox("","passed here")
end try

PowerBuilder crushes (the window 'w_prova' doesn't exist) but the messagebox "passed here" shows.

I bypassed this problem using the 'LibraryDirectory' function and getting the list of windows of my application. I then check if the 'w_prova' is one of them.
Even if it works and is faster then I thought (less then a second to retrieve 200 windows), I don't like it very much, but it looks like there's no other way.

Anyway, thank you very much for help and suggestions.
 
Code:
w_data_sheet w_sheet1
try
  OpenSheetWithParm(w_sheet1, '', 'w_prova', w_sheet1, 0, Original!)
catch (Runtimeerror rt0)
	
	string ls_message
	ls_message = 'Error Number:'+string(rt0.number) & 
	+'.~r~nError Text :'+rt0.text &   
	+'.~r~nError Line:'+string(rt0.line) + '.'
	messagebox('',ls_message)
end try
as above,when the window 'w_prova' doesn't exist,exception can be caught ,and the application will continue.
 
hi,i May Find another way to check if en object is exists.
Code:
String ls_libraries[]
String ls_LibraryList 
ls_LibraryList  = GetLibraryList(),
of_parsetoarray(ls_LibraryList ',',ls_libraries[])//a custom function to parse a string to an array
ClassDefinition cd_windef
cd_windef = FindClassDefinition('w_prova',ls_libraries)
IF isnull(cd_windef) then
  Messagebox('','NULL')	
ELSE
  Messagebox('',cd_windef.name)
END IF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top