#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13

    Why Can't I get a For loop working


    I cant see what I am doing wrong in this for loop. I can do it easy in PHP, but because I am new to Delphi I just don't get it.Can some one point me in the right direction?
    Code:
    procedure TMainForm.CdrButtonOKClick(Sender: TObject);
    var
    i : integer;
    j : integer;
    k : pchar;
    begin
    Assignfile(CdrText, CdrImportEdit.Text);
    Reset(CdrText);
    while not EOF(CdrText) do begin
    ReadLn (CdrText, Buffer1);
    ExtVar := PhoneNum(buffer1);
    for i = strlen(Pchar(ExtVar)) downto 1 do
    begin
    areacode := copy(ExtVAr, 0,i) : string;
    mySQLCollexClient.Query.PrepareTask (Pchar(SELECT * FROM stdcodes
    WHERE areacode = '+areacode,nil,nil,AnyThreadedError;
    SQLClient.Execute;
    j := mySQLCollexClient.Query.DataCount;
    SQLClient.Query.Clear;
    if j > 0 then break;
    end;
    begin
    mySQLCollexClient.Query.PrepareTask (Pchar(SELECT * FROM stdcodes
    WHERE areacode = '+areacode,nil,nil, AnyThreadedError;
    SQLClient.Execute;
    k := mySQLCollexClient.Query.Data;
    SQLClient.Query.Clear;
    end;
    edit1.Text := (ExtVar);
    end;
    CloseFile(CdrText);
    end;
    Errors---------------------------------------

    [Warning] datacollex.pas(117): Comparing signed and unsigned types - widened both operands
    [Error] datacollex.pas(117): For loop control variable must be simple local variable
    [Error] datacollex.pas(118): Expression expected but 'BEGIN' found
    ------------------------------------------------
    WhaDaYaTink?
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,625
    Rep Power
    4247
    For one thing, you have:
    for i = strlen(Pchar(ExtVar)) downto 1 do
    when it should be (notice the := )
    for i := strlen(Pchar(ExtVar)) downto 1 do

    Also, this line won't work:
    areacode := copy(ExtVAr, 0,i) : string;

    Remove the ":string" from the line. Hope this helps
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    Can't shake the PHP monkey.

IMN logo majestic logo threadwatch logo seochat tools logo