Mega Code Archive

 
Categories / Delphi / ADO Database
 

Database access from console application

Title: Database access from console application Question: How can I get database funtionality in a console application? Answer: We need to use ado components. (Delphi 7) The application will run in a terminal emulation on slnet telnet server. In the current solution, I create a Tcomponent and I use it as parent of other Ado components, but the slnet raise and error "The application currently running is a windowed application and cannot be seen from SLNet" program Radio; {$APPTYPE CONSOLE} uses windows, SysUtils, Classes, Global_KER_01 in '..\Librerias\Global_KER_01.pas', DatamodBase in '..\Librerias\DatamodBase.pas' {dmBase: TDataModule}, Global_EQC_01 in '..\Librerias\Global_EQC_01.pas', Global_EQC_02 in '..\Librerias\Global_EQC_02.pas', Global_ERP_01 in '..\Librerias\Global_ERP_01.pas', Global01 in '..\..\Librerias\General\Global01.pas', Global_Radio_01 in 'Global_Radio_01.pas', Radio_Obj_01 in 'Radio_Obj_01.pas'; procedure ExecuteProgram; var c:String; begin Consola := GetStdHandle(STD_OUTPUT_HANDLE); if (Consola INVALID_HANDLE_VALUE) then Cls(Consola) else Write('Error al inicializar la Aplicacin'); Application := TComponent.Create(nil); try dmBase := TdmBase.Create(Application); Repeat if not Conectar then Exit; Menu; until False; finally Write('Pulsa enter para salir.');Readln(c); Application.Free; end; end; begin try ExecuteProgram; except //Handle error condition Raise; Writeln('Programa termin debido a un error.'); //Set ExitCode 0 to flag error condition (by convention) ExitCode := 1; end; end.