Results 1 to 5 of 5

Thread: [lazarus]meh. dunno whats wrong lol

  1. #1
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default [lazarus]meh. dunno whats wrong lol

    im making a simple calculator for math, since my calculator doesnt have what i need(standard deviation formula)

    i attatched my source folder, and here are my error messages:
    when build in lazarus:

    when ran through the desktop application:

    running it through lazarus should (hopefully) explain every thing.
    Last edited by Awkwardsaw; 04-03-2010 at 03:35 AM.
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  2. #2
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    You didn't attach "multicalc.pas"

  3. #3
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by bullzeye95 View Post
    You didn't attach "multicalc.pas"
    i could have swore i did.. 1 sec

    edit: added
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  4. #4
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    You are using the wrong defined TIntegerArray. Futhermore, you are using StrToInt, which may throw errors if the input string isn't a real number.. Oh, and you forget to set the size of the result in GetNums.

    Try this:

    pascal Code:
    unit multicalc;

    {$mode objfpc}{$H+}

    interface

    uses
      Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
      ComCtrls, StdCtrls;

    type

      { TForm1 }

      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Memo1: TMemo;
        Memo2: TMemo;
        PageControl1: TPageControl;
        TabSheet1: TTabSheet;
        procedure Button1Click(Sender: TObject);
        procedure Edit1Change(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { private declarations }
      public
        { public declarations }
      end;

    type
      TStringArray = array of String;
      TIntegerArray = array of Integer;
    var
      Form1: TForm1;
      str : Array of Extended;
      nums : Array of Extended;
    implementation

    { TForm1 }

    //took from simba, stringutil file
    function Explode(del, str: string): TStringArray;
    var
      i,ii : integer;
      lastpos : integer;
      lenstr : integer;
      lendel : integer;
      lenres : integer;
      matches : boolean;
    begin;
      lastpos := 1;
      lenres := 0;
      setlength(result,lenres);
      lendel := length(del);
      lenstr := length(str);
      //  for i := 1 to lenstr do
      i := 1;
      while i <= lenstr do
      begin;
        if not ((i + lendel - 1) > lenstr) then
        begin
          matches := true;
          for ii := 1 to lendel do
            if str[i + ii - 1] <> del[ii] then
            begin
              matches := false;
              break;
            end;
          if matches then
          begin;
            inc(lenres);
            setlength(result,lenres);
            result[lenres-1] := Copy(str,lastpos,i-lastpos);
            lastpos := i+lendel;
            i := i + lendel-1;//Dirty
            if i = lenstr then //This was the trailing delimiter
              exit;
          end;
        end else //We cannot possibly find a delimiter anymore, thus copy the rest of the string and exit
          Break;
        inc(i);
      end;
      //Copy the rest of the string (if it's not a delimiter)
      inc(lenres);
      setlength(result,lenres);
      result[lenres-1] := Copy(str,lastpos,lenstr - lastpos + 1);
    end;

    function getnums : TIntegerArray;
    var
      i : integer;
      s : TStringArray;
    begin
      s:= explode(Form1.Edit1.Text, form1.memo1.text);
      SetLength(result,length(s));
      for i := 0 to high(s) do
        result[i] := StrToIntDef(s[i],-1);
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      memo1.Text := 'Numbers (In Order!) example: 0;0;0;1;2;6;76;77;77;98';
      memo2.text := 'Answers';
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i : integer;
      arr : TIntegerArray;
    begin //the error points to here
      arr := getnums;
      for i := 0 to high(arr) do
        memo2.Lines.Add(IntToStr(arr[i]));
    end;

    procedure TForm1.Edit1Change(Sender: TObject);
    begin

    end;

    initialization
      {$I multicalc.lrs}

    end.
    Verrekte Koekwous

  5. #5
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    gracias ray.
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •