Topic: About Image

Hello MVD fans !

I have a project for managing a revue to which I subscribe.
I enter : title, author, revue number, pagination ... and a photo of the cover.

Of course, to each title of this revue, I use the same cover picture.

When saving, MVD saves also the cover but it increments the image file of the revue :

Armen_0218.jpg
Armen_0218(1).jpg
Armen_0218(2).jpg
Armen_0218(3).jpg
Armen_0218(4).jpg
Armen_0218(5).jpg ... and so on.

Armen is the name of the revue and 0218 is number of this revue.

Is there a script (behind OnAfterClick) which could resolve this problem ?

it would verify that the image file already exists and if so it would keep the first one without any incrementation.

I tried to write one but without success.

Thanks for all yours clues.

Regards

JB

Re: About Image

Hello Jean,


There are two approaches : check if file exist or check if file does not exist.


if FileExists('path to the image and name of the image with extension') then
     begin
         Some awesome code
    end;
if not FileExists('path to the image and name of the image with extension') then
        begin
            Some awesome code
        end;

In the situation you described, I'd check for non existence of the file and if true then save to disk and load, else, just load.
This could look like :

with Form1.DBImage1 do
    begin
        if not FileExists('path to the image and name of the image with extension') then
            begin
                HTTPGetFile('URL of the image','path to save image and name of the image with extension',True);
                LoadPicture('path to the image and name of the image with extension');
            end
       else if FileExists('path to the image and name of the image with extension') then
           begin
               LoadPicture('path to the image and name of the image with extension');
           end;
     end;

Hope this helps a little, do not hesitate if you have moire specific questions on the matter.


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: About Image

Hello Matthias

Merci pour ta réponse rapide. C'est bien la philosophie de ce que j'avais commencé à envisager.

Mon souhait est de créer une procédure particulière pour ce genre de chose que j'appellerais par un évènement OnClick.

J'ai un doute. Qu'est-ce qui est préférable ?

- Utiliser la fonction ExtractFilePath (et ExtractFileName) ?

Le but est permettre la mobilité de mon application sur tel ou tel PC.

Peux-tu illustrer les deux cas de figure avec le script qui va derrière ? J'ai un peu de problème avec la syntaxe.
Je t'en remercie par avance

Cordialement
JB

Hello Matthias

Thank you for your quick reply. This is the philosophy of what I had begun to consider.

My wish is to create a special procedure for this kind of thing that I would call an OnClick event. I have a doubt. What is better?

- Use the ExtractFilePath (and ExtractFileName) function?
The covers folder is called \ Covers

The goal is to allow the mobility of my application on this or that PC.

Can you illustrate the two scenarios with the script that goes behind? I have a bit of a problem with the syntax.
I thank you in advance

cordially
JB

Re: About Image

Please attach your project, with steps to repeat this bug.

Dmitry.

Re: About Image

Hello Dmitry

Thanks for your interest

In attachment, my project.
I've coded it with MVD 3.7b (18/09/2017)

This probleme occured when I save a new record with the same cover.
(i.e , with number 0218, I enterd height records with differents title and domaines,
but they have all the same cover from number 0218).
When I push Save button, in folder Covers, the same picture  of the revue 0218
is incremented +1 each time).

Thanks again

JB

Post's attachments

Attachment icon ARMEN.rar 968.13 kb, 403 downloads since 2017-09-25 

Re: About Image

Bonjour Jean,


J'ai jeté un œil sur ton code et j'ai vu que tu utilisais les fonctions automatiques de MVD (ce qui est très bien). Cependant, je ne sais pas si tu peux éviter la multiplication des images en procédant de la sorte. C'est une fonction de Windows me semble t'il que ce renommage automatique pour éviter les écrasement de fichiers et, à moins que Dmitry ne rajoute une option pour passer outre, je ne vois pas comment l'éviter sans coder toute la procédure de sauvegarde.


En l'état actuel, tu peux vérifier si le fichier existe déjà (en comparant les noms de fichiers dans le répertoire avec le nom du fichier chargé dans le composant DBImage), mais comme c'est le composant DBImage qui au final se charge de la sauvegarde, cela n'a aucun effet.


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: About Image

Check it out

var
    gl_ImageFileName: string;
    gl_FileExists: boolean;

procedure Affichage_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
    gl_ImageFileName := Affichage.DBImage1.dbFileName;
    gl_FileExists := FileExists( ExtractFileDir(Application.ExeName)+ Affichage.DBImage1.dbCopyTo+'\'+ExtractFileName(gl_ImageFileName) );
end;

procedure Affichage_Button1_OnAfterClick (Sender: string);
Var
    i : Integer;
    sFile: string;
begin
    Form1.Grille_Armen.dbUpdate;
    i := Form1.Grille_Armen.RowCount;
    Form1.Label2.Caption := 'Il y a ' + IntToStr(i) + ' fiches';

    if (Affichage.DBImage1.dbImageIsChanged) and (gl_FileExists) then
    begin
        sFile := ExtractFileDir(Application.ExeName) + Affichage.DBImage1.dbCopyTo+'\'+ExtractFileName(Affichage.DBImage1.dbFileName);
        DeleteFile(sFile);
        SQLExecute('UPDATE Armen SET Couverture_filename="'+Affichage.DBImage1.dbCopyTo+'\'+ExtractFileName(gl_ImageFileName)+'" WHERE id='+ IntToStr(Affichage.Button1.dbGeneralTableId) );
    end;

end;

Project:

Post's attachments

Attachment icon ARMEN_fixed.zip 568.16 kb, 432 downloads since 2017-09-26 

Dmitry.

Re: About Image

Hello Dmitry (and Mathmatou)

Very well !

Your two scripts make the job and well !

I imagined that it was necessary to test the presence of the image involved and if it was present, do not increment it, but I was annoyed by the writing of the script

Thanks again for those 2 scripts.
I placed them in my snippet collector.

Regards

JB