Solved

Event list in my component

Posted on 2002-06-17
2
139 Views
Last Modified: 2010-04-04
Hey there ,
I write a component that do couple animations .
What I need is to create a property alike Lines on Memo component where to store a commands list ( alike Goto,DoThis...). When I give run I wish that my component to read each line and execute it .

Any codes ?

For another 100 points ... how can I execute a string as code ?
Alike'Label1.Color:=clRed' to change the label color ?
This is just an example . I don't know what the user wish .
0
Comment
Question by:ginsonic
2 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 100 total points
ID: 7085935
Hi,
Something like:
-----
uses Classes, Extctrls;

type
  TCodeImage = class(TImage)
  private
    FLines: TStrings;
  protected
    procedure SetLines(Value: TStrings);
    function ExecLine(Value: string): boolean;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Run;
  published
    property Lines: TStrings read FLines write SetLines;
  end;

implementation

constructor TCodeImage.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FLines := TStringList.Create;
end;

destructor TCodeImage.Destroy;
begin
  FLines.Free;
  inherited Destroy;
end;

procedure TCodeImage.SetLines(Value: TStrings);
begin
  FLines.Assign(Value);
end;

function TCodeImage.ExecLine(Value: string): boolean;
begin
  result := true;
//  Do exec here
end;

procedure TCodeImage.Run;
var
  i: integer;
begin
  if FLines.Count > 0 then begin
     for i := 0 to FLines.Count - 1 do begin
       if not ExecLine(FLines[i]) then begin
//         Raise exception or ShowMessage
         break;
       end;
     end;
  end;
end;
-----
Regards, Geo
0
 
LVL 2

Expert Comment

by:333
ID: 7086081
about executing string as code:
http://www.torry.net/scripts.htm has some components that parse strings and execute them. some of them are freeware with source, so you can see how this can be done.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

832 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