Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Konsolenanwendung: prozedur / funktion (https://www.delphipraxis.net/108464-konsolenanwendung-prozedur-funktion.html)

cherry 14. Feb 2008 08:01


Konsolenanwendung: prozedur / funktion
 
Hi ich nochmals...

Kann man in Delphi Konsolenanwendungen keine eigenen Prozeduren und Funktionen erstellen? wen ja: Wie? und wenn nein: Wiso?
;-)

Gruss

sirius 14. Feb 2008 08:18

Re: Konsolenanwendung: prozedur / funktion
 
Klar kann man das.
Delphi-Quellcode:
program Konsolenanwendung;

uses windows,...;

{$AppType Console}

function test:integer;
begin
  result:=5;
end;



{main}
begin
  writeln(test);
  readln;
end.
Aber besser ist es zusätzliche Units zu verwenden.

Tyrael Y. 14. Feb 2008 08:19

Re: Konsolenanwendung: prozedur / funktion
 
Klar kannst du das...wenn du eine neue Konsolenanwendung anlegst sieht es folgendermassen aus.

Delphi-Quellcode:
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, Unit2;

var varMyClass;
begin
 

  try
  { TODO -oEntwickler -cKonsole Main : Hier Code einfügen }

   varMayClass := TMyClass.Create();
   try
    varMyClass.TuWas();
   finally
     varMYclass.Free;
   end;

   MachWas();
   NochWas();
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
end.
Da wo jetzt "Hier Code einfügen" steht da kannst du eigenen Code einfügen.

Du kannst, um es auch bissel modularer zu halten dir jetzt eine neue Unit machen, dort Klassen, Funktionen usw. definieren und sie dann von hier aus aufrufen.

Delphi-Quellcode:
unit Unit2;

interface

type
  TMyClass = class
   procedure TuWas();
end;

function MachWas(): TEinTyp;

procedure NochWas();

implementation

end.

taaktaak 14. Feb 2008 08:20

Re: Konsolenanwendung: prozedur / funktion
 
Moin, Moin,

warum sollte das nicht gehen? Schau mal hier...

Delphi-Quellcode:
program Project1;

{$apptype console}

uses Sysutils;

  procedure HelloWorld;
  begin
    writeln('hello world');
  end;

begin
  HelloWorld;
  readln;
end.

cherry 14. Feb 2008 08:31

Re: Konsolenanwendung: prozedur / funktion
 
Vielen Dank euch...

Wusste nicht wo die funktion hinschreiben... ich versuchte es im begin / end teil...
da ist es offensichtlich fehl am Platz....

Dank Euch...

SirThornberry 14. Feb 2008 09:29

Re: Konsolenanwendung: prozedur / funktion
 
Zitat:

Zitat von cherry
Hi ich nochmals...

Kann man in Delphi Konsolenanwendungen keine eigenen Prozeduren und Funktionen erstellen? wen ja: Wie? und wenn nein: Wiso?
;-)

Gruss

Ich liebe die deutsche Sprache:
Zitat:

Kann man...KEINE...erstellen? wenn ja: Wie?
In dem man es einfach nicht macht :wink:

cherry 14. Feb 2008 09:30

Re: Konsolenanwendung: prozedur / funktion
 
:-D lol


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:06 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz