Solved

Calling Procedure or Method in Run Time via DialogBox

Posted on 1998-06-28
9
143 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
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
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.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 127
Multiple image collision 13 74
SUM 2 INTEGER ARRAYS INTO 1 10 100
Convert MS Word document to a PDF file 9 78
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

18 Experts available now in Live!

Get 1:1 Help Now