Delphi-PRAXiS
Seite 2 von 6     12 34     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Funktion erstellen (https://www.delphipraxis.net/26182-funktion-erstellen.html)

Matze 19. Jul 2004 19:41

Re: Funktion erstellen
 
Probier's mal so:

Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure happy(app, icon, destfile: String);
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.happy(app, icon, destfile: String);
begin
   ShowMessage('Anwendung = ' + app + #10#13 + 'Icon = ' + icon + #10#13 + 'Ausgabedatei = ' + destfile);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  happy('Test.exe', 'test.ico', 'c:\test');
end;

end.

Luckie 19. Jul 2004 19:41

Re: Funktion erstellen
 
Komplette Unit:
Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure ShowText(s: String);
begin
  ShowMessage(s);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowText('Foobar');
end;

end.

Andreas L. 19. Jul 2004 19:42

Re: Funktion erstellen
 
Zitat:

Zitat von Luckie
Nur mal aus Neugier: Bist du nicht auch das mit dem HTML Editor: http://www.delphipraxis.net/internal...ct.php?t=30150 ? Wenn ja, kannst du mir mal verraten, wie du das geschafft hast ohne zu wissen wie man Funktionen implementiert und aufruft? :gruebel:

Hää???

Ähn ja, ich habe immer ne UNit eingebunden und dann zum Beispiel das hier verwendet: ForceDirectories(blabla);

Aber bei mir befindet sich die selbstgemachte Funktion in der selben Unit.

---Bernhard--- 19. Jul 2004 19:42

Re: Funktion erstellen
 
Hi!
Zitat:

Zitat von onlinehome
Delphi-Quellcode:
function happy(app : String; icon : String; destfile : String;): String;
begin
   ShowMessage('Anwendung = '+app+#10#13+'Icon = '+icon'+#10#13+'Ausgabedatei = '+destfile);
end;

Da ist ein kleiner Fehler drinn und zwar ein nicht abgeschlossener String!
So müsste es (eigentlich) heißen:
Delphi-Quellcode:
function happy(app : String; icon : String; destfile : String;): String;
begin
  ShowMessage('Anwendung = '+app+#10#13+'Icon = '+icon+#10#13+'Ausgabedatei = '+destfile);
end;
Bernhard :hi:

[edit]:shock: :wall: Da lässt man sich beim Antworten mal bischen mehr Zeit... :mrgreen: :roll: [/edit]

Matze 19. Jul 2004 19:43

Re: Funktion erstellen
 
@onlinehome: Siehe Luckie's oder mein Code oben. ;)

Rackergen2 19. Jul 2004 19:47

Re: Funktion erstellen
 
Zitat:

Zitat von onlinehome
Zitat:

Zitat von Luckie
Ob Prozedur oder Funktion ist erstmnal egal. Sie muss nur vor deiner Button Klick Routine irgend wo unter Implementation stehen.

Aha, und was genau muss ich bei Implementation hin schreiben.

Die Delphi-Hilfe hilft mir auch nicht weiter.

:-(

nirgends, wenn du sie nur happy nennst
Nebenbei habe ich die richtige Funktion schon lange oben gepostet!

Andreas L. 19. Jul 2004 19:48

Re: Funktion erstellen
 
Habs geschafft:

Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure createautorunfile(app : String; icon : String; destfile : String);
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 createautorunfile('Test.exe','test.ico','C:\test');
end;

procedure TForm1.createautorunfile(app : String; icon : String; destfile : String);
var
 sl : TStringList;
begin
   sl:=TStringList.create;
   sl.add('[autorun]');
   sl.add('OPEN=' + app);
   sl.add('ICON=' + icon);
   sl.SaveToFile(destfile+'.inf');
   ShowMessage('Finished!');
end;

end.
Meint ihr meine kleine Procedure soll in die CodeLib. Net wirklich, oder?

Matze 19. Jul 2004 19:51

Re: Funktion erstellen
 
Zitat:

Zitat von onlinehome
Delphi-Quellcode:
procedure TForm1.createautorunfile(app : String; icon : String; destfile : String);
var
 sl : TStringList;
begin
   sl:=TStringList.create;
   sl.add('[autorun]');
   sl.add('OPEN=' + app);
   sl.add('ICON=' + icon);
   sl.SaveToFile(destfile+'.inf');
   ShowMessage('Finished!');
end;
Meint ihr meine kleine Procedure soll in die CodeLib. Net wirklich, oder?

Ähm, nö, net wirkluich. ;)

Rackergen2 19. Jul 2004 19:52

Re: Funktion erstellen
 
Delphi-Quellcode:
function TForm1.createautorunfile(app : String; icon : String; destfile : String):boolean;
var
 sl : TStringList;
begin
  result:=true;
  try
    sl:=TStringList.create;
    sl.add('[autorun]');
    sl.add('OPEN=' + app);
    sl.add('ICON=' + icon);
    sl.SaveToFile(destfile+'.inf');
  except
    result:=false;
  end;
end;

end.
So kommt es besser...

Matze 19. Jul 2004 19:53

Re: Funktion erstellen
 
Wenn dann noch mit Pos überprüfen, ob eine dateiendung bereits vorhanden ist...

So ist er nicht gut. ;)
Edit: Und s1 wieder freigeben!


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:30 Uhr.
Seite 2 von 6     12 34     Letzte »    

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-2025 by Thomas Breitkreuz