Page 1 of 1

[Issue] Close form by macro - access protection of forms

Posted: Sun Jul 13, 2008 9:41 am
by bvdbos
I want to implement some kind of simple access control on my forms. I have a form which I only want myself to be able to access. When loading the form I check for the OS-username. If the function returns false the form closes. This works well. However, on second attempt to open the document the macro's don't get called on startup. After manually closing and reopening the form the startup macro's do work, fourth they don't etc.

Code: Select all

Sub onloadpersoneelsdossier
if checkpermissionspersoneelsdossier = "false" then
'thisComponent.CurrentController.Frame.close( true )
thisComponent.CurrentController.Frame.dispose()
exit sub
end if   
end Sub

function checkpermissionspersoneelsdossier as string
Dim oForm, oCtrl, oState, oCtrl2, oField, naam
oForm=ThisComponent.Drawpage.Forms.getByName("MainForm")
   If GetGuiType = 1 Then
      naam = Environ( "USERNAME" )   ' Windows
   ElseIf GetGuiType = 4 Then
      naam = Environ( "USER" )   ' Unix, Linux
   Else
      MsgBox "Unknown operating system!", 16           
' Mac OS => GetGuiType = 3
   End If
msgbox("sluiten")
'if naam<>"Bas"  then
checkpermissionspersoneelsdossier="false"
'end if
end function
I suppose this is an error in OOO2.4.1, I've run into somthing similar before. Does anyone have an idea how to accomplish the permissions system per form? Of course, I could just offer the forms and set the permissions on my mysql-database per table (I should do that anyway to prevent other users from reading the data through the tables) but I also want to protect the forms.

Re: close form by macro - access protection of forms

Posted: Sat Jul 19, 2008 9:09 am
by bvdbos
No responses here and on oooforum, filed bug 91830.

Re: [Issue] Close form by macro - access protection of forms

Posted: Sun Jul 20, 2008 11:17 pm
by rmdemi
Hello Bvdbos,

I think your code is buggy :!:

In general, a function is not responsible to access your variables and to chance them. Functions takes variables from calling sub, and some extra variables and They returns soma variables to subs... Take a look some sample function codes, you see this.

But your function tries to reach your dialog and I think to set a label called naam.

So You must try your code (checkpermissionspersoneelsdossier) as sub not a function. And you can create a module level variable checkpermissionspersoneelsdossier="false"

I Think this way is correct way.

Re: [Issue] Close form by macro - access protection of forms

Posted: Mon Jul 21, 2008 7:29 am
by bvdbos
Supposing your right, can a sub return have a return-value?

If delete the function and assign the variable "checkpermissionspersoneelsdossier" at the start of the sub the behaviour stays the same.

Code: Select all

Sub onloadpersoneelsdossier
checkpermissionspersoneelsdossier="false"
if checkpermissionspersoneelsdossier = "true" then 
	ResizeWindow
	verbergopmerkingen
	setpersoneelsdossier(true)
       exit sub
end if
'thisComponent.CurrentController.Frame.close( true ) 
thisComponent.CurrentController.Frame.dispose()
end Sub
thanks for helping to solve this.

gr

Bas

Re: [Issue] Close form by macro - access protection of forms

Posted: Mon Jul 21, 2008 6:12 pm
by rmdemi
Hello Bvdbos,
Supposing your right, can a sub return have a return-value?
Of course a sub can,

Code: Select all

Private booleandossier as String  ' This declaration must be first at module

Sub onloadpersoneelsdossier
checkpermissionspersoneelsdossier
if booleandossier = "false" then
'thisComponent.CurrentController.Frame.close( true )
'Using endExecute disposing method for cleaning memory
'thisComponent.CurrentController.Frame.dispose()
oForm.endExecute()
exit sub
end if   
end Sub

sub checkpermissionspersoneelsdossier
Dim oForm, oCtrl, oState, oCtrl2, oField, naam
oForm=ThisComponent.Drawpage.Forms.getByName("MainForm")
   If GetGuiType = 1 Then
      naam = Environ( "USERNAME" )   ' Windows
   ElseIf GetGuiType = 4 Then
      naam = Environ( "USER" )   ' Unix, Linux
   Else
      MsgBox "Unknown operating system!", 16           
' Mac OS => GetGuiType = 3
   End If
msgbox("sluiten")
'if naam<>"Bas"  then
booleandossier = "false"
'end if
end Sub
So in this way, you can reach this variable. Have a look http://user.services.openoffice.org/en/ ... ose#p16042 this subject about dispose.

Try code...

Re: [Issue] Close form by macro - access protection of forms

Posted: Mon Jul 21, 2008 8:54 pm
by bvdbos
endExecute() isn't a method of oForm unfortunately...