Solved

Loading and executing a custom script

Posted on 2004-04-25
6
137 Views
Last Modified: 2010-04-05
Hey guys/gals.
I have a question.. and i've broken ma head over this.  
Its sorta like Scripting
now i open a txt file and enter the following.

------------------
!StartHome*1*Procedure1
OpenFile c:\startup.exe
MoveFile c:\opener.exe c:\winxp\yah.exe
!endHome*1

!StartHome*2*Procedure2
OpenFile c:\somefile.exe
MoveFile c:\gaim.exe c:\games\gaim.exe
!endHome*2
---------------------------- now i save this txt file.
Now in my delphi app. i load this file to a memo or richedit. and i wana read it in this way.
i wana search for "!StartHome" First and then see wat item number it is. - item "1" then i wana look for "!endHome*<itemnumber>" like "!endHome*1"

now i wana be able to get the lines between ItemProcedures. like in Proc1. i should get the lines between starthome and endhome. and i wana read each and everyline after starthome*1 to endhome*1. the number of lines between them can be random. In such a scenario.
how am i able to start coding? just to read the lines.

thx
celina
0
Comment
Question by:sesycelina
  • 2
6 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10911254
Hi

//To read text file into memo
Memo1.Lines.LoadFromFile('YourFileNmae');

//to search first line with !StartHome
for i := 0 to Memo1.Lines.Count-1 do
  begin
  if Pos('!StartHome',Memo1.Lines[i]) > 0 then
    begin
// in line i there is text '!StartHome'
    end;
  end;

to search subsequent line start searching not from i := 0;

Hope this help for the beggining.
0
 

Author Comment

by:sesycelina
ID: 10911290
Yea, i kno this, but how do i read the lines between procedures.

like in delphi
begin
//code//
end
i wana read the lines between them.
0
 
LVL 17

Accepted Solution

by:
mokule earned 20 total points
ID: 10911348
So maybe this will help

var
  str: string;
  bRead: boolean;
begin
bRead := False;  // flag for reading
AssignFile(F,'YourFileNmae');
Reset(F);
while not Eof(F) do
  begin
  Readln(F,str)
  if bRead then
    begin
    if Pos('!endHome',str) > 0 then // end of block found
      begin
      break;
      end
    else
      Memo1.Lines.Add(str);
    end
  else if Pos('!StartHome',str) > 0 then // start of block found
    begin
// add counter here for not reading the first block but any other
    bRead := True;
    end;
  end;
CloseFile(F);
end;
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 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

17 Experts available now in Live!

Get 1:1 Help Now