I found another example of a unit that requires heavy processing, so I decided to move the calculations to the auxiliary program. As opposed to the first procedure in the auxiliary program that calculates correlations, when this procedure finishes, it 'tells' the main program to locate a specific form and update its display; if the form is not displayed then it should be displayed. This part was interesting to program and displays the utility and capabilities of the auxiliary program.
Unfortunately, translating the database code to the format required had me knocking my head against a wall for two hours. I wrote previously that I am using the InterBase components as this makes initialising the database easier especially as I am writing a text-only unit. Whilst it may make initialising the database easier, it makes it harder to write the rest of the code.
I considered this problem whilst walking the dog and decided that I was going to convert the program to dbExpress. The first option would be to see how a visual program defines the database connector then use that in the auxiliary program. If that didn't work, then I would convert the console program to a visual program that won't display its forms. Fortunately the first option worked.
I opened a datamodule from one of my programs and converted the dfm file to text. Here are the definitions that I needed
object SQLConnection1: TSQLConnection ConnectionName = 'IBConnection' DriverName = 'Interbase' GetDriverFunc = 'getSQLDriverINTERBASE' LibraryName = 'dbexpint.dll' LoginPrompt = False Params.Strings = ( 'DriverName=Interbase' 'Database=.... 'RoleName=RoleName' 'User_Name=sysdba' 'Password=masterkey' 'ServerCharSet=' 'SQLDialect=1' 'ErrorResourceFile=' 'LocaleCode=0000' 'BlobSize=-1' 'CommitRetain=False' 'WaitOnLocks=True' 'Interbase TransIsolation=ReadCommited' 'Trim Char=False') VendorLib = 'gds32.dll' Connected = True Left = 56 Top = 8 end
This became converted to
connection:= TSQLConnection.create (nil); with connection do begin with params do begin values['database']:= s; values['DriverName']:= 'Interbase'; values['User_Name']:= 'sysdba'; values['Password']:= 'masterkey'; values['SQLDialect']:= '1'; values['RoleName']:= 'RoleName'; values['CommitRetain']:= 'false'; values['WaitOnLocks']:= 'True'; values['Trim Char']:= 'False'; end; VendorLib:= 'gds32.dll'; LoginPrompt:= false; LibraryName:= 'dbexpint.dll'; ConnectionName:= 'IBConnection'; DriverName:= 'Interbase'; GetDriverFunc:= 'getSQLDriverINTERBASE'; connected:= true; end;
Once I got past this, I quickly converted all the queries from TIBQuery to TSQLQuery and deleted all the lines that were concerned with transactions. For a change, this worked almost straightaway (there were a few minor matters that required manual changes).
This procedure defined a new paradigm for forms and I'll probably find more
units that can be converted to this approach. I don't intend to write
anymore about this auxiliary program.
Title | Tags | ||
---|---|---|---|
296 | Mocha too goes on holiday | Dog | |
418 | Dennis Ritchie: The man who created Unix | Obituary, RIP | |
1179 | Conditional choose-field trigger (2) | Priority tips |
No comments:
Post a Comment