Solved

STRING CODE EXECUTE

Posted on 2002-04-19
5
194 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
Comment Utility
You have to use an interpreter for it... check out

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

Expert Comment

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

Expert Comment

by:ginsonic
Comment Utility
listening
0
 

Author Comment

by:ghjlk
Comment Utility
// 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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 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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

14 Experts available now in Live!

Get 1:1 Help Now