Because the "wincrt" app's have vanished in Delphi 2.0, and the Win32 console
app is so poorly documented, and because a frequently asked question is : can I
have database access without visual components ?, and because I needed both, I
thought an example might be useful.
A console app is generated by checking the appropriate option in the linker page
of the project options. You have to write the source code yourself in a .DPR
file. The example also shows how to access an SQL database without login prompt.
The code by itself serves no useful purpose, I just had to try out the thing.
program Project1;
uses Windows,
SysUtils,
Controls,
Forms,
db,
dbTables;
var
q : Tquery;
d : Tdatabase;
s : String;
i : Integer;
r : Integer = 1;
begin
Application.Initialize;
Application.ProcessMessages;
try
d := Tdatabase.Create(Nil);
d.AliasName := 'watcom5_nt'; { BDE/ODBC alias }
d.DatabaseName := 'watcom';
d.Params.Add('USERNAME=dba;PASSWORD=sql');
d.Loginprompt := False;
d.Open;
q := Tquery.Create(Nil);
q.DatabaseName := 'watcom'; { database name or BDE alias if no Tdatabase}
q.Name := 'Query1';
write('Return starts query');
readln(s);
q.Close;
q.SQL.Clear;
q.SQL.Add('Select * from tel where telno >= 101');
q.Open;
q.First;
while not q.Eof do begin
writeln('Record : ' + IntToStr(r));
for i := 0 to q.FieldCount - 1 do
begin
with q.FieldDefs.Items[i] do begin
write( Name+':');
writeln(q.FieldValues[Name]);
end;
end;
writeln;
q.Next;
end;
writeln('That's it !!'+#10+#13);
Write('Return to exit');
readln(s);
finally
d.Destroy;
q.Destroy;
end;
end.
------------------------------------------------------------------------
Danny Heijl
---
Danny.He...@cevi.be
AT WORK : | HOME :
---------------------------------
CEVI VZW | Danny Heijl
Bisdomplein 3 | Winterstraat 4
9000 Gent | 9000 Gent
Belgium | Belgium
---------------------------------