Solved

need some speed

Posted on 2002-04-15
8
188 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
[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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month4 days, 22 hours left to enroll

636 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