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

    Join Date
    Apr 2017
    Rep Power

    Creating an automatically generated locked field

    I need to create an automatically generated locked field (that can't be a free entry). This field looks like this (this is an example): 2-0103-1/2017. In this example, number 2 represents the number of department in which the document is created. Number 0103 is a date in the form month and day.

    Number 1 is the ordinal number of a document for current day. This field needs to be auto incremented as long as there are documents for the same (current) day. After the day ends, it should be restarted to 1.

    Field 2017 represents the current year.

    My question is, how to implement this in Delphi? What is the easiest way? Is it by using database triggers (I am using MSSQL) or application logic (through Delphi coding). Could someone please explain?

    Please give detailed explanation on how to implement this (either way).

    Could you give concrete code sample snippets (in Delphi or in database triggers)?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Rep Power
    It's probably best to accomplish this in a database table trigger.
    Some things to consider:
    if your application is not the only way the user can access the database, then your application specific code will fail to run if the user uses that other method
    Even if your application is the only way to access the code, two (or more) users running your application would need a central location to determine the next correct value
    If only one user, using only one instance of your application can access the database, then it would be ok to implement in the application.
    In the last case, you would only need to implement a "locking" scheme to generate the next value if your application was multi-threading.
    In that case, lookup TCriticalSection on how to implement that.

IMN logo majestic logo threadwatch logo seochat tools logo