Solved

Loading and executing a custom script

Posted on 2004-04-25
6
141 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
[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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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