Solved

Loading and executing a custom script

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi : could not find program, '...exe' 2 168
Find and Replace Stream with 0s 8 62
Multi-layered image in FireMonkey 9 33
Twebbrowser add css to the header 3 24
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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