Is it possible to change a Resource Type on the fly?

Is it possible to change a Resource Type on the fly?

Postby dpaterso » Wed Feb 22, 2006 6:50 am

Is there any way to change the actual type of a resource from within your application?

Let us say that you have a dialog defined in a .RES file (created with BRW 4.5) and on that dialog you have defined, let us say, five gets.

Is there any way from within your application to sort of 'redefine' those gets so that they 'become' says for example?

Note that this is not the same as defining gets in your resource and then trying to use those get definitions as says by using disabled gets in your application. I am talking about actually changing the resource type as defined in your .res file so that to your application it appears that the gets that you have defined in your .res file are says (the difference between an EDITTEXT and a LTEXT resource for example).

The problem (well not so much a problem but just a pain) is that in the application that I am creating I find myself having to create at least three identical dialogs (for add, edit, and view screens) and the only difference between these dialogs is that some of the gets become says etc. etc. and this just seems a very cumbersome way of doing things.

Regards,

Dale.
dpaterso
 
Posts: 142
Joined: Tue Jan 24, 2006 9:45 am
Location: South Africa

Re: Is it possible to change a Resource Type on the fly?

Postby Enrico Maria Giordano » Wed Feb 22, 2006 7:38 am

Just use WHEN or READONLY clause of the GET objects (or bWhen and lReadonly instance variables).

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby dpaterso » Wed Feb 22, 2006 7:58 am

OK - well that works - sort of.

The cursor is still flashing though even although you cannot edit the get.

I have tried 'Set Cursor Off' and SetCursor( .F. ) - still have cursor.

Also - your ordering stays the same (something I did not think of) i.e. in my 'Edit' Dialog Box the first Get is numbered (ordered) 1 but in my 'Vew' Dialog Box the 1 is the OK button. This (I don't think) is a problem if you can turn the cursor off.

Regards,

Dale.
dpaterso
 
Posts: 142
Joined: Tue Jan 24, 2006 9:45 am
Location: South Africa

Postby James Bott » Wed Feb 22, 2006 8:08 am

Dale,

The problem (well not so much a problem but just a pain) is that in the application that I am creating I find myself having to create at least three identical dialogs (for add, edit, and view screens) and the only difference between these dialogs is that some of the gets become says etc. etc. and this just seems a very cumbersome way of doing things.


No, no, no. We are not in Kansas anymore Toto! ;-)

Unlike DOS apps, in Windows apps there is only one mode-edit mode. You can use the same dialog for all three functions, add, edit, and view. Build one edit dialog. To view the data, the user just opens it for editing and Cancels when done. To make it into an add screen, I just set a var lAdd:=.t. then when the edit routine is called if lAdd then blank the fields, and edit. When the OK button is clicked, check for lAdd and if .t. then append and save else just save. Simple.

This is even much easier if you use database classes. Database classes have built in buffers which makes canceling easy. Have you read the articles about this I wrote? You can find them here:

http://ourworld.compuserve.com/homepages/jbott/program.htm

Part II explains the add/edit methods in detail.

The beauty of this approach is that you can create one class that does most of this, then you just need to create a subclass to add the specifics for each file (item, customer, etc.). Even simpler!

Watch out for that Wicked Witch--she will lead you down the wrong road. :-)

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby dpaterso » Wed Feb 22, 2006 10:03 am

Well, OK.

But the reason that I have to have add, edit, and view displayed differently is because of (intended) system security i.e. if a user does not have sufficient priveleges to add, or edit, or add only or edit only, and can only view (by double clicking on a record for example) then the screen must appear differently to that user.

Are you saying that a 'view' screen would look identical to an 'edit' screen except for the fact that when they click on 'OK' the changes just wont be saved?

Regards,

Dale.
dpaterso
 
Posts: 142
Joined: Tue Jan 24, 2006 9:45 am
Location: South Africa

Postby James Bott » Wed Feb 22, 2006 10:21 am

Dale,

OK, security is a different issue. If the user doesn't have add rights, I would disable the Add button. If they don't have edit rights to anything, then I would disable all the controls on the edit screen except the Cancel button. The easiest way would probably be:

for i:=1 to len( oDlg:aControls )
oDlg:aControls[i]:disable()
next

Then you will have to renable the Cancel button, since it will have been disabled by the above. The Cancel button is usually the last control so you should be able to just use len( oDlg:aControls) -1.

Alternately, you could disable them all with a WHEN clause but it seems like that would be more work.

So, using these techinques you still only need one screen.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Enrico Maria Giordano » Wed Feb 22, 2006 10:25 am

dpaterso wrote:The cursor is still flashing though even although you cannot edit the get.


Use WHEN .F. instead of READONLY and you will not have the cursor.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Enrico Maria Giordano » Wed Feb 22, 2006 10:33 am

James Bott wrote:No, no, no. We are not in Kansas anymore Toto! ;-)


I would like to understand this joke. Can you explain it? :-)

James Bott wrote:Unlike DOS apps, in Windows apps there is only one mode-edit mode. You can use the same dialog for all three functions, add, edit, and view. Build one edit dialog. To view the data, the user just opens it for editing and Cancels when done. To make it into an add screen, I just set a var lAdd:=.t. then when the edit routine is called if lAdd then blank the fields, and edit. When the OK button is clicked, check for lAdd and if .t. then append and save else just save. Simple.


Did you have a peek at my source code? :-) Even the variable have the same name. :-)

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Enrico Maria Giordano » Wed Feb 22, 2006 10:34 am

dpaterso wrote:But the reason that I have to have add, edit, and view displayed differently is because of (intended) system security i.e. if a user does not have sufficient priveleges to add, or edit, or add only or edit only, and can only view (by double clicking on a record for example) then the screen must appear differently to that user.


WHEN clause seems the be the most effective tool for that.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Wed Feb 22, 2006 10:53 am

Enrico,

I would like to understand this joke. Can you explain it?


It is from the 1939 movie, The Wizard of Oz. If you haven't seen it, a girl and her dog, Toto, get swept away in a hurricane to a very strange place, and she says that to her dog.

http://www.moviewavs.com/cgi-bin/moviewavs.cgi?Wizard_Of_Oz=oz6.wav

Did you have a peek at my source code? Even the variable have the same name


Fine minds think alike! ;-)

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Enrico Maria Giordano » Wed Feb 22, 2006 11:03 am

James Bott wrote:It is from the 1939 movie, The Wizard of Oz. If you haven't seen it, a girl and her dog, Toto, get swept away in a hurricane to a very strange place, and she says that to her dog.


Yeah!

James Bott wrote:Fine minds think alike! ;-)


:lol:

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 63 guests