Solved

Calling Procedure or Method in Run Time via DialogBox

Posted on 1998-06-28
9
146 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
Industry Leaders: 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

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!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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