Autor Beitrag
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 17.12.05 15:51 
Hallo!

Ich möchte den folgenden Quellcode in eine Procedure bzw in eine Function packen um diese dann über einen Button aufzurufen!
Wie mache ich das? :roll:


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
begin
if CheckTray.checked = true then
begin
ShowWindow(Application.Handle, SW_HIDE);
    Ico := TIcon.Create;
    Ico.Handle := LoadIcon(HINSTANCE, 'MAINICON');
    d.cbSize := sizeof(d);
    d.hIcon := Ico.Handle;
    d.WND := self.Handle;
    d.uID := 0;
    d.uCallbackMessage := MSG_IconCallback;
    d.uFlags := NIF_MESSAGE or NIF_ICON;
    Shell_NotifyIcon(NIM_ADD, @d);
    Application.OnMinimize := form1.ApplicationEvents1Minimize;
    Application.OnRestore := form1.ApplicationEvents1Restore;
end
else
begin
Shell_NotifyIcon(NIM_DELETE,@d);
ShowWindow(Application.Handle, SW_SHOW);
end;
end;
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Sa 17.12.05 15:56 
Ich würde dir empfehlen, das ganze in eine Procedure zu packen, gehen würde das ungefähr so:
ausblenden 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:
{type
  TForm1 = class(TForm)}

    procedure DoSomething(Sender: TObject);{ falls Parameter benötigt werden: TForm1.DoSomething(Parameter: String/Integer/etc.);}


procedure TForm1.DoSomething; {falls Parameter benötigt werden: TForm1.DoSomething(Parameter: String/Integer/etc.);}
Begin
  If CheckTray.Checked = True Then
  begin
    ShowWindow(Application.Handle, SW_HIDE);
    Ico := TIcon.Create;
    Ico.Handle := LoadIcon(HINSTANCE, 'MAINICON');
    d.cbSize := sizeof(d);
    d.hIcon  := Ico.Handle;
    d.WND := self.Handle;
    d.uID := 0;
    d.uCallbackMessage := MSG_IconCallback;
    d.uFlags := NIF_MESSAGE or NIF_ICON;
    Shell_NotifyIcon(NIM_ADD, @d);
    Application.OnMinimize := form1.ApplicationEvents1Minimize;
    Application.OnRestore  := form1.ApplicationEvents1Restore;
  End
  Else
  Begin
    Shell_NotifyIcon(NIM_DELETE,@d);
    ShowWindow(Application.Handle, SW_SHOW);
  End;
End;


Der Aufruf:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject);
Begin
  DoSomething; {falls Parameter benötigt werden: DoSomething('Hallo'/5/etc.);}
End;
Marc. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 17.12.05 16:17 
Tut mir leid, vllt habe ich dich einfach falsch verstanden, aber wenn ichs so mache, wies da steht, kommt folgender fehler:

ausblenden Delphi-Quelltext
1:
[Error] Unit1.pas(53): Undeclared identifier: 'DoSomething'					


lass ich's "TForm1." weg heißt es:
ausblenden Delphi-Quelltext
1:
[Error] Unit1.pas(53): Not enough actual parameters					


was für parameter muss ich setzen?


--------------------------------------------------------------
ich mein sowas funtzt ja:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TEST;

begin
 showmessage('TeST');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 test;
end;
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Sa 17.12.05 16:24 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TEST;

begin
 showmessage('TeST');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 test;
end;

Natürlich funzt das, damit kannst du allerdings keine Komponenten ansprechen ("CheckTray" z.B.) und das willst du ja.

@ Parameter: das musst du schon selber wissen, was du für Parameter brauchst, In diesem Fall aber wahrscheinlich gar keine.

ausblenden Delphi-Quelltext
1:
2:
3:
{type
  TForm1 = class(TForm)}

    procedure DoSomething(Sender: TObject);

Hast du vielleicht vergessen, die Procedure zu deklarieren?
Insignificant
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Mi 21.12.05 21:06 
Hi, also ich habe das mal eben getestet mit

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure Enablesidebar(Sender: TObject);


procedure TForm3.Enablesidebar(Sender: TObject);
begin
 showmessage('TeST');
end;


procedure TForm3.Button1Click(Sender: TObject);
begin
Enablesidebar;
end;


Funktioniert genauso wenig!
Marc. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 21.12.05 21:32 
das hier...
ausblenden Delphi-Quelltext
1:
procedure Enablesidebar(Sender: TObject);					

kommt ja auch ...

ausblenden Delphi-Quelltext
1:
2:
3:
type
  TForm1 = class(TForm)
  procedure Enablesidebar(Sender: TObject); // <= .. da hin!
;)


übrigens: Es funktioniert einwandfrei bei mir! Danke für eure hilfe! ;)


Zuletzt bearbeitet von Marc. am Fr 23.12.05 22:16, insgesamt 1-mal bearbeitet
Insignificant
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Do 22.12.05 13:14 
Da hab ichs doch auch stehen ^^, darum isses ja auch so weit oben, nur ich hab nicht meinen ganzen Code kopiert. Funktionieren tut es mir trotzdem nicht.
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Fr 23.12.05 10:03 
user profile iconInsignificant hat folgendes geschrieben:
Da hab ichs doch auch stehen ^^, darum isses ja auch so weit oben, nur ich hab nicht meinen ganzen Code kopiert. Funktionieren tut es mir trotzdem nicht.

Kapieren ist besser als kopieren! :P

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Insignificant
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Fr 23.12.05 10:55 
Ja das ist schon klar, nur ich versteh ja nicht warum es nicht funktioniert, da ich es ja so gemacht habe, wie hier angegeben.
Amateur
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 777

(Win98, WinMe) WinXP Prof
D3 Prof, D6 Pers, D2k5 Pers., Turbo C++ Explorer
BeitragVerfasst: Fr 23.12.05 22:30 
ich liebe diese links aber sie würden bei solchen problemen wirklich weiterhelfen:
Crashkurs Delphi
und
Delphi Source
und
Delphi Basics für diverse Befehle

_________________
"Kein dummes Gerede. Kein Rumrätseln. Denkt an nichts anderes mehr, nur noch an das, was vor euch liegt. Das ist die wahre Herausforderung. Ihr müßt euch vor euch selbst schützen, Leute." (Rennes in "Cube")
Beiträge: >700