Solved

need some speed

Posted on 2002-04-15
8
165 Views
Last Modified: 2010-04-04
hello,
i need to get the first char of memo string then validate it,if it is for ex an 'a' then read next char and add to first so i have a3 or a2 etc and also read next char to see if its a 1 or a 0 to set the boolean,i imagine theres a faster way to do this so i only do stuff with results of s and b at end instead of after every check.
also need a break in it so if i click a seperate button it stops the loop imediatly.
there is only about 10 chars that are legitamite for first char (for ex a,c,g,f,t,y,m,j,L,c)if its not one of them i can break also with a message that char is not legitamite<sp>

global var
breakloop : boolean;

local var
s,func ,io ,what: string;
b : boolean;
i : integer;

for i := 0 to form1.memo3.lines.count -1 do begin
s := form1.memo3.lines.Strings[i];
 if pos('L',s) > 0
   then
    form1.button15.Click //create seperate thread loop
    else
 if pos('a',s) > 0
         then begin
         func := 'a';
         delete(s,1,1);
         io := copy(s,0,1);
         delete(s,1,1);
        what := copy(s,0,1);
        if pos('1',what) > 0 then b := true else b:= false;
         s := func+io;

//do stuff with s and b

end
    else
 if pos('b',s) > 0
         then begin
         func := 'b';
         delete(s,1,1);
         io := copy(s,0,1);
         delete(s,1,1);
        what := copy(s,0,1);
       if pos('1',what) > 0 then b := true else b:= false;
         s := func+io;

//do stuff with s and b

memo will be filled like:
a11
a40
c51
f41
L
g10
g11
h31
j90

ive been having some probs with internal error T2261 when trying to put breaks in as the loop is much longer than above so i let someone else have a go.



Regards Barry
0
Comment
Question by:inthe
  • 4
  • 3
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6941621
use a while-loop instead like

while (condition) and not (exitflag) do
  //your stuff

meikl ;-)
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6941638
hi Barry,

fast way would be to use Case statement and do not delete character from the source string, just collect result in another variable.

Break shouldn't be a problem for usual FOR statemnt, seems memory damaged somewhere. Also
Copy(S, 0, 1) looking strange for me. Seems it should be: Copy(S, 1, 1);

btw, cn you show source string and exact result after processing, I will try to make it faster.

------
Igor.
0
 
LVL 17

Author Comment

by:inthe
ID: 6941704
source string will be for memo line

a11
a40
c51
f41
L
g10
g11
h31
j90

so first is "a11"

this is related to the other q so i know which checkbox to set on or off.

the first time the loop reads this it shoud check a1
the second line should uncheck a4 ,third time will check c5 etc..
i tried using a case statement but because i was having probs passing it strings .

so result will be first
 a1 with b = true
 then
 a4 with b = false
 then
 c5  with b = true
0
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 6941753
What happens with "L"? There is no trail character "1" nor "0".

btw, I think that code should be something like this:

var
  C: TComponent;
  S: String;
  I: Integer;
begin
  for I := 0 to Memo1.Lines.Count - 1 do
  begin
    S := Memo1.Lines[I];

    C := FindComponent(Copy(S, 1, Length(S) - 1)); // extract the name of component
    if C is TCheckBox then
      (C as TCheckBox).Checked := Copy(S, Length(S), 1) = '1'; // set it checked if last character is "1"
  end;
end;

-----
Igor


0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 17

Author Comment

by:inthe
ID: 6941754
btw,
i agree it seems odd ,
Copy(S, 1, 1);
and
Copy(S, 0, 1);
is doing same thing here now ,maybe cause im deleting the first char each time.i had to use it on another routine for parsing a xml file that had control characters in it
i copied and pasted it without thinking really
i suppose i could also do
 func := 'i';
 io := copy(s,2,1);
 what := copy(s,3,1);
s := func+io ;

so for a11 i have s = to a1 and what = to 1
0
 
LVL 17

Author Comment

by:inthe
ID: 6941763
the L is to start a seperate thread running a different loop on different memo.seeing your example now it looks so obvious


0
 
LVL 17

Author Comment

by:inthe
ID: 6941769
Igor
i can simply change the L part to fit in with rest of it so no worries.

thanks
Regards Barry
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6941792
Thanx Barry,
always wellcome :-)
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

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

25 Experts available now in Live!

Get 1:1 Help Now