Question

I'm working to a program that use different type of SQL database servers. Inside this program I play a lot with this items.

This is how I define the static list now:

type 
  TServerType = (stNone, stMsSQL, stMySQL, stSQLite);

Now, I would like to associate to this static list the short name and the long name of the server like this:

stNone    | (null) | (null)
stMsSQL   | mssql  | Microsoft SQL
stMySQL   | mysql  | MySQL
stSQLLite | sqlite | SQLite

Is it possible to do this directly by using this type? (can be done without var or const and array)

Or how do you recommend the best to define this associated list?

Was it helpful?

Solution

A static array will work for that:

type 
  TServerType = (stNone, stMsSQL, stMySQL, stSQLite);

  TServerNames = record
    ShortName: String;
    LongName: String;
  end;

const
  ServerNames: array[TServerType] of TServerNames = (
    (ShortName: ''; LongName: ''),
    (ShortName: 'mssql'; LongName: 'Microsoft SQL'),
    (ShortName: 'mysql'; LongName: 'MySQL'),
    (ShortName: 'sqlite'; LongName: 'SQLite')
  );

var
  ServerType: TServerType;
  ShortName: String;
  LongName: String; 
begin
  ServerType := ...;
  ShortName := ServerNames[ServerType].ShortName;
  LongName := ServerNames[ServerType].LongName;
  ...
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top