Solved

Calling Procedure or Method in Run Time via DialogBox

Posted on 1998-06-28
9
142 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 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

22 Experts available now in Live!

Get 1:1 Help Now