Solved

need some speed

Posted on 2002-04-15
8
172 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
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.

 
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
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error E2158 compiling with Delphi XE10 Seattle 2 99
Delphi inherited method 6 68
RESTRequest Parameter 4 30
MS Access from Delphi 31 28
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

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