Autor Beitrag
finalizat0r
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 24
Erhaltene Danke: 1



BeitragVerfasst: Sa 12.05.12 15:40 
Hallo,

wie der Titel schon beschreibt will ich per Code zur Laufzeit (beim Start der Anwendung) entscheiden, ob {$APPTYPE CONSOLE} über der uses-Klausel verwendet wird oder nicht.
Ich hab mir das in etwa so gedacht
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
uses
  SysUtils;

const
  Visibility: Boolean = false;

{$IF Visibility}
  {$APPTYPE CONSOLE}
{$IFEND}

procedure SetVisibility(const Value: Boolean);
begin
  Move((@Value)^, (@Visibility)^, SizeOf(Boolean));
end;

function GetVisibility(): Boolean; // nur proforma
begin
  Result := Visibility;
end;

begin
  try
    if ParamStr(2) = '-show' then
      SetVisibility(true);

    if GetVisibility then
      ReadLn;
  except
    on E: Exception do
      WriteLn(E.ClassName, ': ', E.Message);
  end;
end.
was leider nicht funktioniert, da das Kompiler-Direktive {$IF } nur absolute Konstanten verwendet/verwenden will/wie man es auch nennen möchte...

Was wohl bedeuten soll:
ausblenden Delphi-Quelltext
1:
2:
const
  MyConst = true
funktioniert (wobei hier die SetVisibility-Procedure versagt, da sie den Wert für die Konstante nicht setzen kann), und
ausblenden Delphi-Quelltext
1:
2:
const
  MyConst: Boolean = true
nicht funktioniert.

Ich hab mir schon überlegt das über eine seperate Anwendung laufen zu lassen, das über einen Parameter entscheidet ob
die sichtbare Konsolenanwendung extrahiert wird oder eben die nicht sichtbare Anwendung (...was eigentlich Quatsch wäre, finde ich :lol:)

Gibts für sowas eine Lösung? Hab nichts per Google oder Forum-Suche gefunden (oder einfach falsche Stichwörter benutzt :nixweiss: )

Mit freundlich Grüßen
final
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Sa 12.05.12 15:53 
www.delphiforum.de/viewtopic.php?t=109150

Die Variante von Bummi könnte was für dich sein :)

Für diesen Beitrag haben gedankt: finalizat0r
finalizat0r Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 24
Erhaltene Danke: 1



BeitragVerfasst: Sa 12.05.12 16:02 
Coole Sache :zustimm:, danke für die schnelle Antwort...

Ums nochmal festzuhalten:
user profile iconbummi hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    procedure DebugOut(const s: String);
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    FHasConsole:Boolean;
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
var
  I: Integer;
begin
   for I := 1 to 100 do
      begin
        Caption := IntToStr(i);
        DebugOut('Schleife an Stelle '+ IntToStr(i))
      end;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  FHasConsole := Windows.AllocConsole;
end;

procedure TForm2.FormDestroy(Sender: TObject);
begin
   if FHasConsole then FreeConsole;

end;

Procedure TForm2.DebugOut(Const s:String);
begin
  if FHasConsole then Writeln(s);
end;

end.