Autor Beitrag
Timbo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 166



BeitragVerfasst: Di 25.04.06 16:30 
Hallo,

ich habe eine variable, die ich mit einer Procedure belegen kann. möchte aber vorm ausführen testen, ob sie belegt ist... leider mekert der compiler


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:
TFunction = procedure of Object;
VarFunction: TFunction;

procedure MachWas;
begin
  showmessage('Hallo');
end;

procedure VarFunctionRuecksetzen;
begin
  VarFunction:= nil;
end;

procedure VarFunctionSetzen;
begin
  VarFunction:= MachWas;
end;

procedure VarFunctionAusfuehren;
begin
  if VarFunction <> nil then VarFunction; //hier ist das problem, "incompatible Types"
end;


hat jemand eine idee, wie ich das machen kann?

ein workaround wäre das hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure VarFunctionRuecksetzen;
begin
  VarFunction:= doNothing;
end;

procedure doNothing;
begin
  //
end;

procedure VarFunctionAusfuehren;
begin
  doNothing;
end;


vielen dank.
tim.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 25.04.06 20:19 
ausblenden Delphi-Quelltext
1:
@VarFunction <> nil					


Referenzen-Vergleiche immer mit @ davor ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Timbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 166



BeitragVerfasst: Di 25.04.06 20:26 
Bingo, danke.
Simon Joker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 236
Erhaltene Danke: 1



BeitragVerfasst: Mi 26.04.06 10:43 
Vernünftigerweise sollte man die Funktion
ausblenden Delphi-Quelltext
1:
function Assigned(const P): Boolean;					

nutzen. Das ist eigentlich Standard und wird für jegliche CallBack-Events der VCL genutzt.
Du mußt dich dann auch nicht kümmern, ob du einen Pointer oder eine Procedural-Variable testest.

Bespiel OnClick-Event mit TNotifyEvent.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
...
if Assigned(FOnClick) then
  FOnClick(Self);
...


MfG Simon