Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Testing passing function

Posted on 2002-05-11
10
Medium Priority
?
177 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
  • 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
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.

 
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

824 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