Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

need some speed

Posted on 2002-04-15
8
Medium Priority
?
199 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Accepted Solution

by:
ITugay earned 400 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

722 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