Solved

Testing passing function

Posted on 2002-05-11
10
170 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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 50 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 57
Delphi XE10 Round Image 2 157
Delphi: Connect to running MS Outlook 4 121
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 44
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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