#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Looking for some program architecting advice


    Hey everyone,

    I was wondering if someone can help me out here.

    I'm an old school hobbyist programmer (basic, vb, delphi). I'm what you call dangerous, I know enough to write code but not well enough to handle threading etc.

    In any case this is what I need help with.

    I want to write an application that downloads a list of pictures and data from a web server and display it on a TV monitor in a nice friendly manner.

    My problem is this. I don't know which method is best to design the app.

    Should I be creating a "service" to do the downloading and importing into a database every so often and just get the program to display the info? I've never really created a service so not sure where to start.

    Should I just get the app to spawn a thread to do the downloading and importing into the database. How do I make sure that the thread doesn't kill my app if something during the download process fails.

    As you know the internet is unreliable and I don't want anything such as timeouts, bad downloads etc affecting the displaying of the pics and data.

    Any help would be greatly appreciated.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0
    Seriously? No one?

    Just point me the write direction. I would really appreciate it.

    Please.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    354
    Rep Power
    7
    This is a fairly difficult question to give an answer to since there's many different valid approaches, given that, here's my 2 cents..

    Building a Windows Service to download the files seems like a reasonable approach. If you need some help on how to design such an application, I suggest you read this

    http://www.tolderlund.eu/delphi/service/service.htm

    However, debugging a service application is a bit more difficult than your normal run of the mill application. Additionally, Microsoft also made interacting (from your login/desktop) with a Service in Vista/Win7/Win8 nearly impossible. This means that using MessageDlg/ShowMessage to the desktop just won't work. It also means that you can't trigger another application to start running on your desktop). That of course doesn't mean there aren't options, I've used the component here to set up communication (via named pipes) between my desktop and a service (even though they aren't even running on the same machine)

    http://www.cromis.net/blog/downloads/cromis-imc/

    The approach I take on developing a Service is to build Object(s), that are instantiated from your service. The reason I do this.. It allows me to instantiate the Object(s) from a normal "stub" application, and test the Objects' functionality before I start working on the service. So your object would have the methods necessary to download the files, save them to the database, waiting for the application to tell it to execute..

    Originally Posted by kidjake28
    Should I just get the app to spawn a thread to do the downloading and importing into the database.
    A service can also spawn the thread, just as an application can. The approach is discussed in the Service Tutorial link above. However, if you want more information on how to build threads with Delphi, I suggest you read this:

    http://thaddy.co.uk/threads/

    Originally Posted by kidjake28
    How do I make sure that the thread doesn't kill my app if something during the download process fails.
    This is especially important for a service application. One, because there is no ability to interact with your desktop, an error in the service will crash the service. Secondly, since your service will presumably be up and running 24/7/365 (if the computer running it is on), then any memory leaks (even small ones) spells disaster for it.

    In this case, Delphi's "Try..Finally" and "Try..Except" constructs are your friend. You have to be sure that under NO circumstances errors can "escape" from your service (they must ALL be handled within the confines of your service). If you haven't used these constructs before: Use Try..Finally when memory is allocated, to ensure it is deallocated and use Try..Except blocks anywhere an error is possible (and where aren't they) to capture and handle the error.

    As to storing the downloaded files...

    Nothing beats the data management of a database management system. There are plenty of free ones, which you would have to install on a machine available to the service, possibly even the same machine. To have your application / service connect to the database, I have used the components found here

    http://zeos.firmos.at/

    These components should allow connectivity to MySQL, Postgre, Firebird among others.

    As to actually displaying the files on your Monitor, I would suggest that be another application. A normal Delphi VCL application that has read access to the database system with the graphic files.

    Anyway, hope this gets you started...
    Last edited by majlumbo; April 26th, 2013 at 02:14 PM.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0
    Thank you this is excellent information.

    I appreciate you taking the time and effort with all the links etc.

    I'm starting on this right now!!

IMN logo majestic logo threadwatch logo seochat tools logo