Solved

Calling Procedure or Method in Run Time via DialogBox

Posted on 1998-06-28
9
141 Views
Last Modified: 2010-04-04
20 points ... very hard :)

How to call procedure or method in run time via dialog box ?
for example, while application running, user can pressing special key to call dialog box.
From that dialog user can call any procedure or method.

code, please ...                
0
Comment
Question by:hrizal
9 Comments
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
There are standard dialog functions like MessageDialog, that have standard buttons like OK, Cancel, Yes-No etc.

It goes like:

  if MessageDialog(...) = mrOK then ...

You can construct your own forms to make dialogs. You add buttons to forms and set their ModalResult property so you can modlly show them like this:

  if form1.showmodal = mrOK then ...

I'm not so sure I got you right, so please explain better what you really want to do with dialogs.
0
 
LVL 2

Author Comment

by:hrizal
Comment Utility
question is not about dialog but
code for calling procedure or method.
0
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
...And? What do you mean by that?
0
 
LVL 10

Expert Comment

by:Jacco
Comment Utility
Methods are possible you can get them using the fieldaddress method. But you can only call them if you know the exact prototype. For example you can query a class for all it Notify events and call them with a sender.

Procedure are not possible (I think).

I don't know if it is required to have debug information on when you do such a thing.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Expert Comment

by:Matvey
Comment Utility
What do you mean?? Is it possible to get a list of methods at runtime and call them all???
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
? Never heard it's possible, I know its possible in SAP, but in Delphi? Let me know if it can!!!
0
 
LVL 2

Author Comment

by:hrizal
Comment Utility
In last century, when i am using clipper for main language.
calling procedure from dialog is easy as 123,
when i press ctrl-alt-del (keyboard routine, was hook of course)
dialog box will appears like figure on below

   +----------------------------------------------+
   |        +-----------------------------------+ |
   | Call : | SetPrinter(false)                 | |
   |        +-----------------------------------+ |
   +----------------------------------------------+

                          OR

   +----------------------------------------------+
   |        +-----------------------------------+ |
   | Call : | CloseProgram()                    | |
   |        +-----------------------------------+ |
   +----------------------------------------------+

and then for example i type name of procedure
"setprinter(false)" or "closeprogram()"
when i press enter, application jump to that procedure.

Comment of Jacco, maybe near closer which i want,
is possible calling procedure or method, where the procedure name or method name in string variable ?

in simple :

Procedure WriteIt;
Begin
   Writeln('alley alley alley');
End;

Procedure CallProcedure(PN : String);
begin
  ????? the answer should be here !  
end;

Var ProcName : String;
Begin
   ProcName := 'WriteIt';
   CallProcedure(Procname);
End.
0
 
LVL 3

Accepted Solution

by:
rickpet earned 20 total points
Comment Utility
No you can't do what you want...This is basically only possible in an interperted language...

Basically you are writing the code as you go...(You actually can do this...but we won't go there...as it entitles rewriting your applications memory...).

Now you can query objects for RTTI info on their methods.  The easiest is to use is MethodAddress(Note this info is only available to Methods that are streamed i.e. Forms and Buttons...) here is an example...Click on Button2 to see what happens... (Note you will need to have 2 Buttons...Button1 and Button2)

unit unMethodRtti;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('Button1');
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Meth: TMethod;
begin
  Meth.Data := Self;
  Meth.Code := Self.MethodAddress('Button1Click');
  Button2.OnClick := TNotifyEvent(Meth);
end;

end.
 
0
 
LVL 2

Author Comment

by:hrizal
Comment Utility
Yea .... yea .... all of you are allright.
its possible for interpreter languange.

but, maybe this idea is good for inprise.

Thank all.

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now