Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Console Application..

Status
Not open for further replies.

beginner81

Programmer
Oct 27, 2003
44
MY
I need to implement a console application to take a filename parameter to automatically upload one of the text file (which was given by the client)into the database server, this application should generate the status in a log file. During uploading that files Records, we must use the entered AS400 date and ProductNo (one of the field in that file) to check for whether the record was loaded or not, if loaded then skip this record, otherwise if the old record has ReferenceCount = 0, then will output to log file.

I don't even hav any idea how to write a console application ... so can anyone there help ... roughly giv me the idea what should i do for the above question . ok.. thx for ya help.. since i'ts quite important for me.. thx..
 
Here's some tips for starters:

In Delphi, go to File, New, Other... then double click Console Application.

To refer to the command line, use ParamStr(1). If you're specifying a filename, you may want to force the user to enclose the filename in quotes (because if the filename or part contains spaces it will be seen in Delphi as separate parameters.

Or, even better, if you're only expecting one parameter, just combine ParamStr(1) to ParamStr(9) into one string var with spaces between. A simple loop can do that.

All components you use you'll have to create dynamically, and make sure you Free them at the end. Remember, you don't have a Form with a console application. A console app typically looks something like this:

program ConsoleApp;

uses
...
var
...
procedure A;
begin
end;

function B;
begin
end;

...etc...

begin
{ Program begins running here. Create all your components in here, but make sure you use a try..finally block to Free them all. }

end.


See if that gets you started. Post back if you need help with any of the other issues you mentioned.

 
Thanks for that Griffin.. but here r some of the prob :
1) How am i goin to take a filename parameter to automatically uploading a certain file (let's say its filename is Customer) into the database server ??
2) During uploading the Customer Records, i hav to use the ProductNo (certain field in that file) to check for whether the record was loaded or not, if loaded then skip this record, otherwise if the old record has ReferenceCount = 0, then will output to log file.
How am i goin to do so ??

Thx for help.. and sorry bout that.. cos i'm a newbie in delphi..
 
What sort of database server is it? You'll have to create a TADOConnection component and build an connection string to your database. The easiest way to do this I've found is to create a new normal application and give it a TADOConnection and then use the property editor to point and click your way to a working connection. Then just grab the string it's created and put it into your console application.

Then, make a TADOQuery component, link it to your TADOConnection component, and use the available commands to find records in the table, and/or append or modify records. Use the help file for this, and post back here if you can't work it out.

I don't know what format your input file is, but here's some starters:

var
InFile : TextFile;
s : String;
q : TADOQuery;
begin
q := TADOQuery.Create(nil);
{ Set up any properties for q here }
try
AssignFile(InFile, ParamStr(1));
Reset(InFile);
try
while not EOF(InFile) do
begin
readln(InFile, s);
{ Perform parsing here of s }
q.AppendRecord([...,...,...]); // see help file
end;
finally
CloseFile(InFile);
end;
finally
q.Free;
end;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top