Solved

Calling Procedure or Method in Run Time via DialogBox

Posted on 1998-06-28
9
145 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
[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
9 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1356133
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
ID: 1356134
question is not about dialog but
code for calling procedure or method.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1356135
...And? What do you mean by that?
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 10

Expert Comment

by:Jacco
ID: 1356136
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
 
LVL 3

Expert Comment

by:Matvey
ID: 1356137
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
ID: 1356138
? 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
ID: 1356139
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
ID: 1356140
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
ID: 1356141
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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