-1

i made a program in delphi that upload picture to kinvey provider, first the program saves the image from TImage component in a specific Dir then upload it to kinvey, the issue is every time i open the program it uploads to kinvey, now how to make sure that it only upload one time even if i opened the program multiple times

Image1.Repaint;
Image1.Bitmap.SaveToFile('some dir');
procedure TTabbedwithNavigationForm.Timer2Timer(Sender: TObject);
var
  fn : string;
  Lstream : TFileStream;
  Lfile  : TBackendEntityValue;
begin
 fn := 'the file dir';
 try
Lstream := TFileStream.Create(fn, fmOpenRead);
BackendFiles1.Files.UploadFile(fn,Lstream, 'image/png',Lfile);
finally
Lstream.Free;
BackendFiles1.Free;

end;

end;

end.
markkk
  • 31
  • 2
  • 7
  • Place some information locally about ehich files you have uploaded. – Jens Borrisholt Aug 16 '15 at 18:31
  • 1
    The code is a real mess. Finally block is poor. Code doesn't seem complete. I think you could do better. – David Heffernan Aug 16 '15 at 22:10
  • You either have to store the state somewhere in a persistent way (DB/File System/etc) if you want the application to remember something between instances. Alternatively you could do some sort of cross process communications. Ultimately this should be tied to when the image needs to be updated. – Graymatter Aug 17 '15 at 02:39
  • i can edit the code easily mate, i care just about the problem in my question @DavidHeffernan – markkk Aug 17 '15 at 08:11
  • yeah i think im close to the answer, well, thanks @Graymatter – markkk Aug 17 '15 at 08:12
  • 1
    That attitude is a large part of your problem. You don't care enough about us to make the code legible or even coherent. It doesn't compile and has stray fragments whose context we have to guess at. You did not provide a full MCVE so we cannot know exactly what triggers your code to execute. You do not have an answer yet because your question is very low quality. If you want help, you will address these problems. – David Heffernan Aug 17 '15 at 08:19
  • So just don't run program multiple times. Allow just one instance. – smooty86 Aug 17 '15 at 13:50

1 Answers1

1

The name of the method "Timer2Timer" suggests that this code is triggered... by a Timer component named Timer2. ;-)

Check where this timer is activated. If it is already enabled at design time, the event will be called as soon as the defined time has elapsed, independently from any user interaction.

BTW: It is good to use a try/finally-block for streams, but the stream creation should be directly before "try" (else you would trigger the finally block if the creation of the stream fails, and then you are getting an access violation because the stream variable is not initialized).

The call of "BackendFiles1.Files;" inside the finally-block seems obsolete to me, what should that do?

Udontknow
  • 1,472
  • 12
  • 32