Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Testing passing function

Posted on 2002-05-11
10
Medium Priority
?
176 Views
Last Modified: 2010-04-04
I have callback function and want to make sure that Func only called when it is not nil and make it default to nil.

type
  TCallBack = procedure of object

procedure TBlabla.Loop(Func: TCallBack = nil);
begin
  if Func <> nil then Func;
end;
0
Comment
Question by:comicboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:mikepj
ID: 7003295
"procedure of object" -> "procedure"
"func <> nil" -> "@func<>nil"

0
 
LVL 4

Expert Comment

by:nestorua
ID: 7003315
HI,
What about: if Assigned(Func) then Func.
Sincerely,
Nestorua.
0
 
LVL 2

Expert Comment

by:mikepj
ID: 7003415
Assigned() is the same as <>nil
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:nestorua
ID: 7003418
But more DELPHIable and not the same when TFunc has
parameters, if I am not mistaken.
0
 
LVL 2

Expert Comment

by:mikepj
ID: 7003440
Myself I prefer to use Assigned().  From the Delphi help file:

"Assigned(P) corresponds to the test P<> nil for a pointer variable, and @P <> nil for a procedural variable."
0
 
LVL 4

Expert Comment

by:nestorua
ID: 7003446
That's what I tried to say. Agree with you, mikepj.
0
 

Author Comment

by:comicboy
ID: 7004007
Hi, I'm newbie in Delphi could you please tell me what example of a "ponter variable" and what is "procedural variable" actually in program ?

Anyway both of you expert in this field who should I give the points ?
0
 
LVL 2

Accepted Solution

by:
mikepj earned 200 total points
ID: 7004025
Hi ComicBoy,

The full answer is below.  I have provided the answer you need.  Using a pointer to a procedure is a rather special possibility which I use only rarely (mostly for sorting routines to provide a function which performs the evaluation to decide whether item x should go before or after item y.  A pointer points at something.  Usually a pointer points at a variable but it could point at other things (like a procedure).

Since it sounds like you're a beginner, I would suggest that you think of other ways you might do what you have asked.  It's just that it's a bit advanced and can possibly cause you some frustration if you don't fully understand all the concepts involved.

If you need further help with this, ask away.  It'd be good if you are using pointers and such for you to do some reading about them.  Have fun; very powerful stuff!

MP

unit Unit1;

interface

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

type
  TCallBack = procedure;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure Loop(Func: TCallBack = nil);
  end;

var
  Form1: TForm1;

procedure f;

implementation

{$R *.DFM}

procedure f;
begin
  Showmessage('hi');
end;

procedure TForm1.Loop(Func: TCallBack = nil);
begin
 if (@Func <> nil) then Func;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // let's test it
  Loop(nil);
  Loop(@f);
end;

end.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7014935
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20122794.html
http://www.experts-exchange.com/questions/Q.20122796.html
http://www.experts-exchange.com/questions/Q.20138191.html
http://www.experts-exchange.com/questions/Q.20150902.html
http://www.experts-exchange.com/questions/Q.20245947.html
http://www.experts-exchange.com/questions/Q.20245954.html
http://www.experts-exchange.com/questions/Q.20245949.html
http://www.experts-exchange.com/questions/Q.20299515.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20125957.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 

Author Comment

by:comicboy
ID: 7026946
So sorry for long delay on grading, I'm away awhile from internet reach...

Anyway Thanks alot for your great answer of massive knowledge :) you are a great expert :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question