Solved

need some speed

Posted on 2002-04-15
8
176 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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