Solved

Loading and executing a custom script

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need Delphi function to get Youtube video title 5 225
Correct Component for Shopping Cart. 2 96
Strange behavior when a form is closed 6 51
Reconfigure Delphi Install? 2 46
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

22 Experts available now in Live!

Get 1:1 Help Now