Solved

STRING CODE EXECUTE

Posted on 2002-04-19
5
199 Views
Last Modified: 2010-04-04
STRING CODE EXECUTE

I want to execute string code at runtime.
For example :
-----
Form2.Panel2.Color:=clRed;
-----

Thanks.
0
Comment
Question by:ghjlk
5 Comments
 
LVL 14

Accepted Solution

by:
DragonSlayer earned 300 total points
ID: 6955276
You have to use an interpreter for it... check out

http://www.carlo-kok.com/ifps3.php
0
 
LVL 17

Expert Comment

by:inthe
ID: 6955306
dwscript v2 is also quite popular and can do this:
http://www.dwscript.com/
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6955585
listening
0
 

Author Comment

by:ghjlk
ID: 6955592
// I want to execute code in richedit1.
// Could You give me an example with Your solutions.
// Thanks.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
RichEdit1.Clear;
RichEdit1.Lines.Add('Form2.Panel1.Color:=clRed;');
Form2.Show;
end;

end.




unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm2 = class(TForm)
    Panel1: TPanel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

end.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6955805
Hi ghjlk,

something like this?

uses
   ..., TypInfo,.....

function SetPropertyValue(const FormName, ComponentName, PropName, Value: String): Boolean;
var
  I: Integer;
  C: TComponent;
begin
  Result := False;
  for I := 0 to Screen.FormCount - 1 do
    if CompareText(Screen.Forms[I].Name, FormName) = 0 then
    begin
      C := Screen.Forms[I].FindComponent(ComponentName);
      if C <> nil then
      begin
        if CompareText(PropName, 'COLOR') = 0 then
          SetPropValue(C, PropName, StringToColor(Value))
        else
          SetPropValue(C, PropName, Value);
        Result := True;
      end;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetPropertyValue('Form1', 'Label1', 'Color', 'clRed');
  SetPropertyValue('Form1', 'Label1', 'Left', '10');
  SetPropertyValue('Form1', 'Label1', 'Alignment', 'taRightJustify');
end;

-----
Igor.
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

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…
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…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

16 Experts available now in Live!

Get 1:1 Help Now