Topic: Adding Editing Saving on Same Form

I understand this one requires some script which is beyond me at present. I hope somebody kind and capable enough can help.


https://s28.postimg.org/lsiu0dyul/zzzzz_Temp5.png


Adding/editing and saving on same form not by hiding buttons, panels etc. but actually making buttons and fields disabled as appropriate.


Please see ref. image above...
On default state Add, Edit and Delete buttons are active but fields and buttons under "Add / Edit Record" panel are disabled.
If user clicks Add or edit button  fields and buttons under "Add / Edit Record" panel are enabled.
On add/edit state when user click on save or cancel button then it returns to default state.
Clear button is just for clearing fields.


A sample project attached.

Post's attachments

Attachment icon Adding Editing Saving on Same Form.zip 9.23 kb, 511 downloads since 2017-02-26 

Adam
God... please help me become the person my dog thinks I am.

Re: Adding Editing Saving on Same Form

Hi Adam,
Since all of your fields and buttons are contained within the panel, all you need to do is set the default state of panel1 to enabled = false.
If add or edit is clicked, then the script is simply form1.panel1.enabled := true;  and attach it to the onclick events for the add and edit buttons.
To then disable the panel, attach form1.panel1.enabled := false to the onclick event for the save button.
I think you'd want to check for the user changing their minds, so I'd also disable the panel if they click back in the grid for example etc etc.
I'd also make one of your fields mandatory to prevent blank records being created (or do a pre-save check).
I'm not sure why you want to clear out your fields - if you have more fields than can be displayed in the grid, wouldn't you want your users to see the contents of the fields in the panel?
If it's any use, have a look at the attached - a (very) basic contacts program that does everything on one screen with panels being enabled and disabled (and also buttons hidden / displayed).
Derek.

Post's attachments

Attachment icon contacts one form.zip 344.75 kb, 569 downloads since 2017-02-27 

3 (edited by zahar2002 2017-02-27 07:50:32)

Re: Adding Editing Saving on Same Form

just add function new record to the add button and slect   form1  and the buttons will enabled
then add event
procedure Form1_Button5_OnClick (Sender: string; var Cancel: boolean);
begin
     Form1.edLastName.SetFocus ;
end;

4 (edited by AD1408 2017-02-27 18:34:22)

Re: Adding Editing Saving on Same Form

Hi Derek and zahar2002,


Thanks a lot guys.......................


I have done it with enable/disable buttons only. It seems to be working OK but I'm not sure if all correct and not missing/overlooking to something. Updated sample project attached.


Derek,
1. I couldn't get working to display record details on mouse click and scroll without SQL in my sample project (using buttons enable/disable?
2. I have no idea about writing custom procedure like derekon without (Sender: string) etc. When you have time your short tutorial would be much appreciated.


-------
Edit: I realized that I missed enabling/disabling fields, therefore updated the sample project accordingly.

Post's attachments

Attachment icon Adding Editing Saving on Same FormB.zip 11.55 kb, 525 downloads since 2017-02-27 

Adam
God... please help me become the person my dog thinks I am.

5 (edited by derek 2017-02-27 21:57:34)

Re: Adding Editing Saving on Same Form

Hi Adam,
1.  As I said in an earlier post, any field, button etc that is contained within a panel is subordinate to the settings of that panel.  So it's just one line to enable or disable a panel AND all the objects within it rather than all the extra lines of code you have by doing it object by object.  I'm not sure why you do it that way.
2.  Is there a reason why you mix the 'enabled' and the 'visible' properties?  Enabled=false means that the user sees the object but can't click into it whereas Visible=false means that the user can click into it but then can't type.  Personally, I think it might be confusing for the user.
3.  I've just quickly modified your project so that you can scroll or click through the grid and display values in the edit fields;  this is achieved by issuing an 'edit' click in the script every time you scroll or click in the grid.  In effect you are permanently in 'edit' mode - the script then repositions you back onto the highlighted grid row to give the effect of scrolling and displaying. 
4.  The actual edit button that is visible on the form is fake!  What it actually does is to enable / disable your panels.
It takes a few minutes to get your head around this approach and there are other ways of achieving the same effect (duplicate forms, for example, which personally I prefer as it uses more of standard MVD).
Derek.

Post's attachments

Attachment icon Adding Editing Saving on Same Form.zip 342.76 kb, 546 downloads since 2017-02-27 

Re: Adding Editing Saving on Same Form

Hi Derek,


Thank you very much for the latest update..........
Very kind of you and appreciated


I liked your custom/global procedure that makes tGrid auto row selection great if I understood correctly. In this case there is no need for refresh after delete/edit/ save.


I prefer the approach of; if a button is not clickable then it should be displayed as disabled. I'm not saying it's better but just a personal preference.
So, I did buttons enable/disable with panels version. I also added clear script to cancel button. If I didn't make a mistake attached sample project is exactly what I wanted do. I couldn't have done it without your help.


Is there a reason why you mix the 'enabled' and the 'visible' properties?  Enabled=false means that the user sees the object but can't click into it whereas Visible=false means that the user can click into it but then can't type.  Personally,

I may have made a mistake without realizing. My understanding of "Enabled=false means that the user sees the object but can't click" and Visible=false means that the user cannot see or click into the component where property visible set to false. i.e. I put a button on a form with Visible=false, on run I cannot see or click on it. Perhaps you are trying to explain something else and I'm not getting it?

Post's attachments

Attachment icon Adding Editing Saving on Same Form 3.zip 11.69 kb, 539 downloads since 2017-02-28 

Adam
God... please help me become the person my dog thinks I am.

Re: Adding Editing Saving on Same Form

Hi Adam,
A 'senior moment' on my part! 
What I was querying was the mix of 'enabled' and 'read only' properties (not 'enabled' and 'visible', as I wrote in my previous response).
Apologies for the confusion.
Derek.

Re: Adding Editing Saving on Same Form

Hi Derek,


This one could have been in it's own topic. It's partially connected to this thread.


Showing record details without SQL script works fine when adding/editing on same form. I was wandering is it possible to do same (without SQL script) when adding/editing done on different form?


Please see the sample project attached.

Post's attachments

Attachment icon Showing details without SQL.zip 9.97 kb, 523 downloads since 2017-03-01 

Adam
God... please help me become the person my dog thinks I am.

Re: Adding Editing Saving on Same Form

Hi Adam,
Yes, it's very much possible and what I was referring to in a previous post - duplicate form processing (for want of something better to call it - LOL!).
So all I've done is take your attachment and made the two forms look identical.  To the user it seems like it's all on the same form.
But by using two forms, you play to the strengths of MVD and don't have to worry about the extra problems that using a single form creates (toggling enabled/disabled objects, refreshing grids, accidently creating duplicate records etc).   And creating a second, identical form is pretty quick - just set the overall new form's dimensions to be the same and then copy and paste the objects across.
Derek.

Post's attachments

Attachment icon Showing details without SQL.zip 343.61 kb, 556 downloads since 2017-03-01 

Re: Adding Editing Saving on Same Form

Thanks a lot Derek...........................


I love derekscroll... in this case myscroll as you have changed it to demonstrate it could be any name.
I didn't need a tgrid on adding editing details  form (frmEmpployee), so I deleted it. Added couple of lines for save button on frmEmpployee so that it focuses on newly added record and display details.


-------------

Post's attachments

Attachment icon Showing details without SQL 2.zip 17.48 kb, 552 downloads since 2017-03-01 

Adam
God... please help me become the person my dog thinks I am.