Topic: Some issues with my very first project

Here is attached my very first project. Hopefully, it is not the last one.
I am trying to make a simple database for storing of few text info along with picture and attached files (for each record) but in separate files called “storage” and “gallery” following the lot of examples, tips and instructions from this forum (in English and Russian language).
I’ve been struggling with this for over a month but I still haven’t been able to do it the right way.
There are a some issues I can't solve and professional help will be very appreciated.
1.- From the very beginning, problems with storing and deleting files into and out of "storage" and "gallery" occasionally occur. For example, it happens Form2 shows no photo in picturebox and / or no attachment in DBFile1 even though they still exist in storage and gallery. The opposite happens too, ie the picturebox and DBFile1 show attached files even though they are not in the storage and gallery (somehow are deleted). Also, very often if I change the photo in picturebox, the old photo still exist in gallery (it is not deleted).
2.- I tried to make limit of records in TableGrid with this code:

            procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
         begin
     if form1.tablegrid1.rowcount >= 10  then form3.show  else form2.show;        

 end;

At the same time I changed the Properties and Events of "Add" button to "no action" and "Form1 Button1 OnClick". It seems to me it is working but the new problem arrives. When I click the Add button, the form opens but with no empty fields. The fields are filled with the previous record.
3.- I have a DateTimePicker in Form2 that should be included and visible in TableGrid1 and print report too.
Report printing in both cases seems to be OK (Printing one record or printing all the records). Only the Recorded Date is missing in print report, because is missing in TableGrid1 too.
I rely on the help of Derek and other experts from this forum.
Thanks in advance.

Post's attachments

Attachment icon MyProject1.zip 1.17 mb, 232 downloads since 2020-08-17 

Re: Some issues with my very first project

3. не понятно, что Вы хотите

Post's attachments

Attachment icon MyProject1.rar 531.51 kb, 223 downloads since 2020-08-17 

3 (edited by derek 2020-08-17 23:57:58)

Re: Some issues with my very first project

Hi MarkoS, Sibprogsistem,
1.
Deleting files from the 'storage' and 'gallery' folders when changing either a photo or a file was not working because you have not created the 'onafterclick' event between the Form2.Button1 object and the procedure in the script (see screenshot1 in the attachment).  You cannot simply copy and paste code from other projects into your script without also creating these associated 'events'.
2.
Form2.show will display empty fields the first time you start your program and click 'Add'.  But after that, it will always be holding the values from the record you last displayed.  In your script, you should be using 'form2.newrecord' and not 'form2.show (see screenshot2 in the attachment).
3.
If you want the date to default to the current date, you need to select both the 'default checked' and 'checked' properties for the 'datetimepicker1' object (see screenshot3).  If you looked at the raw data, you would see that the date was being saved as 'null' (see screenshot4) which was why nothing was showing in the relevant tablegrids or in the reports.
.
Please have a look at the attached project which contains fixes for all of the above issues.
Regards,
Derek.

Post's attachments

Attachment icon MyProject1 fixed.zip 1.29 mb, 345 downloads since 2020-08-18 

Re: Some issues with my very first project

Thanks, Derek,
That was very valuable.
Without your help, I would have given up.
One more thing.
For other option (with no limits of records) I should:
- delete the part of script related to Form1_ Button1_OnClick
- change the property of Form1.Button1 to New Record
- clear the Events of Form1.Button1
- clear the Events of Form2.Button1
Am I right or wrong again?
Otherwise, I can set the limit to 1000000 eg.

5 (edited by derek 2020-08-18 13:20:10)

Re: Some issues with my very first project

Hi MarkoS,
Yes - if you don't want to limit the number of records, you can
1.  delete the procedure form1_button1_onclick in the script
2.  delete the 'onclick' event associated with form1.button1
3.  change the action associated with form1.button1 from 'no action' to 'new record'
But you need to keep the 'onafterclick' event associated with form2.button1 - this is the event (and 'procedure form2_button1_onafterclick' in the script) that deletes files from the 'gallery' and 'storage' folders when you change an existing picture or an existing document.
Derek.

Re: Some issues with my very first project

Thanks, Derek.

Re: Some issues with my very first project

Hi, Derek,
I tried and it seems to be OK for now.
Just one thing regarding the attachments.
When I click to Open folder with file then opens the whole PC (This PC) instead just the storage folder . I checked out, attachment is really in storage and I can open and delete it  clicking to Open file or Clear.
Is there anything that can be done about it?

Post's attachments

Attachment icon Untitled.png 7.99 kb, 101 downloads since 2020-08-25 

Re: Some issues with my very first project

Hi MarkoS,
It should open the 'storage' folder wien you click on 'Opem Folder with File'.
If it opens up the whole PC (This PC) it's usually because it can't find the folder (or the path to the folder) that the specific file is in.
In the attachment, I've added 2 new buttons to Form2 that open the selected file and the selected folder directly.  Can you see if they work as they should?
If not, can you attach your project and people can have a look and see if they can spot anything.
Derek.

Post's attachments

Attachment icon MyProject1 fixed A.zip 701.1 kb, 233 downloads since 2020-08-25 

Re: Some issues with my very first project

Thanks Derek for your effort. It is really very valuable for me.
Please, see an attached mp4.
The issue could be with two textboxes in Form1, that are either empty (if save button in form2 is clicked) or the same (if the cancel button is clicked). Even when any other row is highligted for deleting they remain the same and it is a question what picture or file will be deleted.

Post's attachments

Attachment icon MyVD.mp4 845.84 kb, 243 downloads since 2020-08-26 

10 (edited by derek 2020-08-26 19:59:06)

Re: Some issues with my very first project

Hello MarkoS,
My bad!  I forgot to clear the edit fields on Form1 when closing Form2.  I think it should be okay now (see corrected attachment).
And thanks for the .mp4 - made it very easy to see exactly what the problem was.
Derek.

Post's attachments

Attachment icon MyProject1 fixed again.zip 736.88 kb, 247 downloads since 2020-08-26 

11 (edited by MarkoS 2020-08-27 17:47:57)

Re: Some issues with my very first project

Hi, Derek,
I have tried many times to attach files and "Open file" as well as "Open folder with file" in both ways.
Your way with the added buttons "Open storage" and "Open file" works without error, but keeping both options is a bit confusing.
It seems to me, I found a reason for the strange behaviour of "Open folder with file" in DBFile.
For some reason, the name of the attachment must not contain "," (comma).
I don't know if it's a bug in MVD, that can be corrected somehow (or bypassed) or is something specific in my PC or I am doing something wrong?
Any advice?

12 (edited by derek 2020-08-28 00:49:58)

Re: Some issues with my very first project

Hi MarkoS,
I've been able to reproduce the problem - it's a strange one!  I'm not sure if it's a bug in MVD or something wider.
Unfortunately, it's nothing that we can fix.  However, please see the attached as a work-around (which also removes one of the options so it is less confusing). 
Click on the 'search' button on Form2 and if you mouse-over either of the labels ('Open Folder (Storage)' or 'Open File'), there is a text hint to tell the user what to do.  Also, when you mouse-over, the cursor turns to the 'handpointer' to alert the user that the label can be clicked.
Hope this fixes the problem.
Derek.

Post's attachments

Attachment icon MyProject1 fixed again and again.zip 754.1 kb, 221 downloads since 2020-08-28 

Re: Some issues with my very first project

Thanks, Derek,
I also thought in a similar way, to cover the right part of DBFile1 with the Panel, but the "delete file" is still missing. Can a delete button be added?
Or prevent the user somehow to add the file with comma.
The best solution would be to completely remove DBFile and add a new table  and the script with the ability to add file (perhaps multiple files); replace, view, and delete files, but I'm quite sure I'll be unable to do that.
Hopefully, I am not so tedious and too demanding.
Any help is really appreciated.

Re: Some issues with my very first project

Please see attached - a 'delete file' option has been added.
From my quick testing, you should now be able to
1)  delete a row in Form1 which will delete the relevant file (if present) and image (if present) in the 'storage' and 'gallery' folders
2)  delete an image in Form2 which will delete the relevant image in the 'gallery' folder
3)  delete a file in Form2 which will delete the relevant file in the 'storage' folder
4)  change an image in Form2 which will replace the old image with the new image in the 'gallery' folder
5)  change a file in Form2 which will replace the old file with the new file in the 'storage' folder.
Images and files can, of course, still be added in the usual way.
All of the above should be okay even if file names include characters such as 'commas'.
Derek.

Post's attachments

Attachment icon MyProject1 fixed 4.zip 577.31 kb, 241 downloads since 2020-08-28 

Re: Some issues with my very first project

Thanks for your great support, Derek.

Re: Some issues with my very first project

It is about the last version: MyProject1 fixed4.
I have noticed that a record can be added even though the limit has been reached in case the "search" button is clicked  and if TableGrid1 contains fewer records than the limit is set.
I tried with the script below.
Is there a better solution?

  procedure Form1_Button4_OnClick (Sender: TObject; var Cancel: boolean);
   begin
   form1.button1.Visible := false;
   end;

Thanks in advance.

17 (edited by derek 2020-09-02 20:35:33)

Re: Some issues with my very first project

Hi MarkoS,
This is because the script checks on the number of rows displayed in form1.tablegrid1 rather than the number of rows held in the table 'example' .
To fix this, just change the form1_button1_onclick procedure to count the number of rows in the table 'example' instead.
But now when the 'search' (filter) is active and the tablegrid is displaying a sub-set of the records, it could be confusing to the user to be warned that the maximum number of records has been reached when the user can only see less than the maximum in form1.tablegrid1.  So it might be helpful to display a counter below form1.tablegrid1.  For example, enter 5 in the 'slots' or 'poles' criteria, then enter 55 and then 555 and you will see the counter changing.
Please see attached.
Derek.

Post's attachments

Attachment icon MyProject1 fixed 5.zip 577.47 kb, 219 downloads since 2020-09-02 

18 (edited by MarkoS 2020-09-06 14:44:17)

Re: Some issues with my very first project

Thanks, Derek,
I found the solution using your explanation.
(BTW, it seems to me in the script is something wrong, the search button disappears somehow).
I have one question more.
Is it possible to add two or three more buttons to form2:
- "Delete record" that will delete existing record  and go back to form1( if it is not too tricky because of attached files)
- "Next record" that will show next record from Form1TableGrid1 (if exists),
- "Previous record" that will show the previous record from Form1TableGrid1 ( if current record is not the first in TableGrid1).
Thanks

Re: Some issues with my very first project

Hi MarkoS,
Please find attached your project.
It now has
1) a 'delete' button on Form 2 that deletes the record (and any associated image and file in the 'storage' and 'gallery' folders) and then returns you to Form1.
2) 'next' and 'previous' buttons on Form2 that scroll through the records shown in Form1.tablegrid1.
The search button on Form1 doesn't show because I'd made it invisible when I was doing some testing.  There is the option in MVD to (optionally) hide the search button and set your search fields (in your example 'slots' and 'poles') to search incrementally - in other words, the user doesn't have to click on the search button - the rows in the tablegrid automatically refresh as the user types into either of the search fields (see screenshot1 in the attachment).  If you prefer to see the 'search' button, just make it 'visible' again and remove Button4 as the 'increm.search' property for the 'slots' and 'poles' search fields.
Derek.

Post's attachments

Attachment icon MyProject1 fixed 6.zip 779.22 kb, 250 downloads since 2020-09-06 

Re: Some issues with my very first project

Thank you, Derek.
It looks marvelous.
I'll try to implement it.