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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiler directive problem

Status
Not open for further replies.

roo0047

Programmer
Jul 31, 2004
533
US
I have a form that I want to make calls from both a console app and from a GUI app. I have a statusbar on the form. Since the form itself is not visible from the console app (it could be but rather not), I want the status updates going to the screen, not the statusbar.

I was hoping the following code would work, but does not.
Code:
procedure TQbExport2MySqlForm.UpdateStatus(Pan: integer; s: string);
begin
{$IF APPTYPE CONSOLE}
  if pan = 0 then write(s + #32) else writeln(s);
{$IFELSE}
  StatusBar1.Panels[Pan].Text:= s;
{$IFEND}
end;
Help?

Roo
Delphi Rules!
 
{$APPTYPE CONSOLE} is more of a status flag than anything directly to do with the compiler. It changes the EXE so it creates the console and can patch into the CLI. As for manipulating the CLI to do this, that's pretty difficult for a number of reasons - perhaps more so in Vista because Microsoft would rather you not have the console app. Anyway, this is the closest I've come to doing what you suggest (detecting the CLI) successfully, though there are write problems with this example.


Perhaps easiest would be to just pass a boolean from the main app that indicates whether it is being called from a console app or from a form app.

Measurement is not management.
 
Actually I just got it working with the following (D7E w/ WXPSP3):
Code:
procedure TQbExport2MySqlForm.UpdateStatus(Pan: integer; s: string);
begin
{$IfDef CONSOLE}
  if pan = 0 then write(s + #32) else writeln(s);
{$ELSE}
  StatusBar1.Panels[Pan].Text:= s;
{$ENDIF}
end;
In Delphi Help, under 'Conditional compilation' I found:
CONSOLE Defined if an application is being compiled as a console application.

Conditional symbols are not Delphi identifiers and cannot be referenced in actual program code. Similarly, Delphi identifiers cannot be referenced in any conditional directives other than $IF and $ELSEIF.
Note: Conditional definitions are evaluated only when source code is recompiled. If you change a conditional symbol's status and then rebuild a project, source code in unchanged units may not be recompiled. Use Project|Build All Projects to ensure everything in your project reflects the current status of conditional symbols.
So, doing a Build rather than Compile made a big difference.

Thanks Glenn!

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top