Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Code Block

Posted on 1999-07-21
9
Medium Priority
?
602 Views
Last Modified: 2010-04-04
Hi experts,
I am trying to write a 'CodeBlock' function (or procedure) in Delphi 3.0, like one in CA-Clipper 5.2 / 5.3. That means I want to bo able to assign to a string variable a value like :

    s := 'Writeln(a); writeln(2*a);'

and later to execute it in the same way as in Clipper :

    eval(<parameter>,s)

where <parameter> are data, over which is evaluated the 'Code Block').

Is this possible in Delphi 3.0 and how can I achieve it ?
0
Comment
Question by:victor_christov
[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
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 2

Expert Comment

by:kotik
ID: 1390348
Hi, Viktor
I don't think that it's possible in Delphi.

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1390349
No, this is not possible in Delphi, although there are some simple language interpreters that can be used in Delphi (take a look at Delphi Super Page http://sunsite.icm.edu.pl/delphi) - this has a couple of these engines on it.

One way you can approximate this is by using DLLs. If you would like more information on this let me know...

Cheers,

Raymond.

0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1390350
Delphi is compiled.  After your program is compiled, it has no clue what Pascal syntax means, or even what Pascal is, because the Pascal is no longer there.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:simonet
ID: 1390351
What you're looking is called a "parser" under Pascal.

There are plenty of them in DSP: http://metalab.unc.edu/delphi
or
http://sunsite.unc.edu.pl/delphi

Alex
0
 
LVL 1

Expert Comment

by:Smilly
ID: 1390352
What you are looking for is lex and yacc,
where lex (lexical analyse) takes a string as input,
and you will get a lot of tookens back, depending on
what rules you have set up.....
And then you put these tookens into the yacc (yet another compiler compiler), wich also have a lot of rules on how the tookens are put together, and then yacc parse and makes up your source code for you....

This is a very huge task, you have to make your own compiler.....

you can find a lex/yacc program wich is called tply for delphi in www.torry.ru

I hope you this help... But good luck......

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1390353
Smilly:

lex and yacc will be about as useful to him as tits on a bull!

Even if he used them and wrote his compiler, he still can't insert the compiled code inline like he wants to do...

Cheers,

Raymond.

0
 
LVL 1

Expert Comment

by:Smilly
ID: 1390354
Hi Raymond,
Sure he can, but it is a big task.
He can make a internal function rule EVAL and tell it to take [pascal] as
parameters.......It is not a big thing, the big thing is to make the compiler.
If it first works then its no big deal to force it to interprete the parameters inside
EVAL(.....).

And as I see it, it is the only way he can do this task.......

0
 
LVL 2

Accepted Solution

by:
kjteng earned 400 total points
ID: 1390355
If my memory doesn't fail me (sorry, the last time I use Clipper 5 was 1994), there are two things in clipper that always got confused: CodeBlock and Macro. I think all the comments are correct but more applicable to macro rather then codeblock.  A code block is actually a unnamed function that has been compiled in pcode. You cannot eval(<parameter>,s)  unless the function named in variable s is already compiled and contained within the same program. On the other hand, macro is intepreted at runtime. You call &S at run time and S can be anything recognisable by the runtime intepreter.

Come back to your question. It is possible to do some thing similar to "codeblock" but not "Macro" in Delphi. It is very simple. By using pointer to function/procedure or procedural type.

Example (using procedural type):

unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
TStrProc = procedure(ii: Integer);

procedure Show1(ii: Integer);
procedure Show2(ii: Integer);

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure Show1(ii: Integer);
begin
  ShowMessage(IntToStr(ii));
end;

procedure Show2(ii: Integer);
begin
  ShowMessage(IntToStr(ii*2));
end;


procedure TForm1.Button1Click(Sender: TObject);
var pp: TStrProc;
begin
  pp := Show1; { similar to s := 'Writeln(a)...' }
  pp(1); {eval....}
  pp := Show2;
  pp(2);
end;

end.

0
 
LVL 2

Expert Comment

by:kjteng
ID: 1390356
Hello Vitor, any comment/question?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

715 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