Results 1 to 9 of 9

Thread: Quick Form Help

  1. #1
    Join Date
    Jan 2007
    Location
    Illinois.. >.<
    Posts
    1,158
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Quick Form Help

    Hey guys, i haven't been around in a while and was just messing around in SCAR and i came across something i don't remember how to do and was wondering if someone could help.. So each time i hit a button on a form, the script adds a number, for the sake of argument, we'll say it's random.. And i'm planning on hitting the button like 5 or 6 times.. Each time i hit the button, i want the numbers that appear in the Memo box to re-order themselves from greatest to smallest.. Can anyone help me out with that? Thank you!

  2. #2
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Hmm... This probably isn't the best way to do it, but it's the first solution that came to my mind..

    Here you go:

    SCAR Code:
    var
      form: TForm;
      memo: TMemo;
      button: TButton;
      TIA: TIntegerArray;

    procedure click(Sender: TObject);
    var
      i: Integer;
    begin
      SetArrayLength(TIA, GetArrayLength(TIA) + 1);
      TIA[High(TIA)]:= Random(999);
      BubbleSortB(TIA);
      Memo.Clear;
      for i:= 0 to High(TIA) do
        Memo.Lines.Append(IntToStr(TIA[i]));
    end;

    function buildForm: Boolean;
    begin
      form:= CreateForm;
      form.SetBounds(0, 0, 100, 150);
      form.Position:= poScreenCenter;
      form.BorderStyle:= bsSingle;
      form.BorderIcons:= [biMinimize, biSystemMenu];
      memo:= TMemo.Create(form);
      memo.Parent:= form;
      memo.SetBounds(0, 0, 117, 90);
      memo.ReadOnly:= True;
      memo.ScrollBars:= ssVertical;
      button:= TButton.Create(form);
      button.Parent:= Form;
      button.Caption:= '*Click*';
      button.SetBounds(0, 90, 117, 28);
      button.OnClick:= @click;
      Result:= (form.ShowModal = mrOK);
    end;

    function loadForm: Variant;
    var
      v: TVariantArray;
    begin
      SetArrayLength(v, 0);
      Result:= ThreadSafeCall('buildForm', v);
    end;

    begin
      loadForm;
      FreeForm(form);
      SetArrayLength(TIA, 0);
    end.

    -Jani

  3. #3
    Join Date
    Jan 2007
    Location
    Illinois.. >.<
    Posts
    1,158
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Can you explain the "high" function to me please? And why it is needed in this line of code:
    Code:
    TIA[High(TIA)]:= Random(999);
    Thanks, sorry i haven't used SCAR in a while

  4. #4
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    High(array) returns the highest index of array, without erroring.

    Basically, you get same results by doing "GetArrayLength(array) - 1".

  5. #5
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    High will get the highest integer in a set of integers I'm pretty sure

    >.> lol stole! </3

  6. #6
    Join Date
    Jan 2007
    Location
    Illinois.. >.<
    Posts
    1,158
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Want to explain why this doesn't order the numbers for me please? Lol it just writes the newer number at the top and that's it?

    Code:
    SetArrayLength(TIA, GetArrayLength(TIA) + 1);
    
      if BandName.Text <> '' then
      begin
        if TwoPlayerBand.Checked then
        begin
          for i:= 0 to 6 do
            begin
              Score := StrToInt(Edit[i].Text);
              if Score <> 0 then
                AvgScore := (Score/2)*4;
              NewScore := NewScore + AvgScore;
              Writeln('Averaged score - '+IntToStr(AvgScore));
            end;
          Writeln('Total score - '+IntToStr(NewScore));
          //TIA[High(TIA)]:= NewScore;
          
          BubbleSortB(TIA);
          ScoreBoard.Clear;
          for a:= 0 to High(TIA) do
          begin
            TIA[a] := NewScore;
            ScoreBoard.Lines.Add(IntToStr(TIA[a]) + ' - ' + BandName.Text);
            Writeln(IntToStr(TIA[a]));
          end;
        end;

  7. #7
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Umm use a Tobject,

    SCAR Code:
    Procedure OkiClick(Sender : TObject);
    Case Sender Of
      Button1 : Begin
                      Inc(Times);
                      Memo1.Clear;
                      Memo1.Items.Add(IntToStr(Times));
                    End;
      End;
    End;

    @Your question you need to use a Clear Procedure, e.g Memo1.Clear

    Also if you want to order your numbers , smallest to Largest your going to have to convert thoose numbers into a TIntegerArray from a TStringArray, then you an alogorathim such as QuickSort or BubbleSort

  8. #8
    Join Date
    Jan 2007
    Location
    Illinois.. >.<
    Posts
    1,158
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I have a clear procedure and i also do sort a TIntegerArray using BubbleSortB, but it still isn't working properly..

  9. #9
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Is it something like this...

    SCAR Code:
    type
      TBands = record
        vocalistPoints, guitaristPoints, drummerPoints,
         bassistPoints, totalPoints: Extended;
        name: string;
      end;

    const
      minB = 1;
      maxB = 20;

    var
      form: TForm;
      labels: array[0..1] of array[minB..maxB] of TLabel;
      lbledits: array[0..4] of TLabeledEdit;
      groupbox: array[0..1] of TGroupBox;
      scrollbox: TScrollBox;
      button: TButton;
      bands: array[minB..maxB] of TBands;

    function accuracy(e: Extended; i: Integer): Extended;
    var
      x: Integer;
    begin
      Result:= e;
      x:= Pos(',', FloatToStr(Result));
      if(x = 0)then
        Exit;
      Result:= StrToFloat(Copy(FloatToStr(Result), 0, x - 1) + '.' + Copy(FloatToStr(Result), x + 1, i));
    end;

    function average(TEA: TExtendedArray): Extended;
    var
      i: Integer;
      e: Extended;
    begin
      try
        SetArrayLength(TEA, GetArrayLength(TEA));
        for i:= 0 to GetArrayLength(TEA) - 1 do
          e:= e + TEA[i];
        Result:= e div GetArrayLength(TEA);
      except
        Result:= -1;
      end;
    end;

    procedure refreshBands;
    var
      i: Integer;
      s: string;
    begin
      for i:= Low(bands) to High(bands) do
      begin
        if(bands[i].name = '')then
          Exit;
        s:= '[Name: ' + bands[i].name + '] ' +
             '[Total Pts: ' + FloatToStr(bands[i].totalPoints) + '] ' +
             '[Vocalist Pts: ' + FloatToStr(bands[i].vocalistPoints) + ',' +
             ' Guitarist Pts: ' + FloatToStr(bands[i].guitaristPoints) + ',' +
             ' Bassist Pts: ' + FloatToStr(bands[i].bassistPoints) + ',' +
             ' Drummer Pts: ' + FloatToStr(bands[i].drummerPoints) + ']';
        labels[1][i].Caption:= s;
      end;
    end;

    procedure add(Sender: TObject);
    var
      i, i2: Integer;
      TEA: TExtendedArray;
      e: Extended;
    begin
      SetArrayLength(TEA, 4);
      for i:= Low(bands) to High(bands) do
        if(bands[i].Name = lbledits[0].Text)then
        begin
          WriteLn('Band exists already!');
          Exit;
        end;
      for i:= 1 to 4 do
        try
          TEA[i - 1]:= accuracy(StrToFloat(lbledits[i].Text), 2);
        except
          TEA[i - 1]:= 0;
        end;
      e:= accuracy(average(TEA), 2);
      for i:= High(bands) downto Low(bands) do
        if(e > bands[i].totalPoints)then
          i2:= i;
      if(i2 > 0)then
      begin
        for i:= High(bands) downto i2 + 1 do
        begin
          bands[i]:= bands[i - 1];
          bands[i]:= bands[i - 1];
        end;
        bands[i].name:= lbledits[0].Text;
        bands[i].vocalistPoints:= TEA[0];
        bands[i].guitaristPoints:= TEA[1];
        bands[i].bassistPoints:= TEA[2];
        bands[i].drummerPoints:= TEA[3];
        bands[i].totalPoints:= e;
        refreshBands;
      end;
      SetArrayLength(TEA, 0);
    end;

    function buildForm: Boolean;
    var
      i, i2: Integer;
      TSA: TStringArray;
    begin
      form:= CreateForm;
      form.SetBounds(0, 0, 500, 300);
      form.Position:= poScreenCenter;
      form.BorderStyle:= bsSingle;
      form.BorderIcons:= [biMinimize, biSystemMenu];
      for i:= 0 to 1 do
      begin
        groupbox[i]:= TGroupBox.Create(form);
        groupbox[i].Parent:= form;
        case i of
          0: begin
               groupbox[i].Caption:= 'Add Band';
               groupbox[i].SetBounds(10, 10, 130, 250);
             end;
          1: begin
               groupbox[i].Caption:= 'Top Bands';
               groupbox[i].SetBounds(150, 10, 330, 250);
             end;
        end;
      end;
      TSA:= ['Band Name', 'Vocalist', 'Guitarist', 'Bassist', 'Drummer'];
      scrollbox:= TScrollBox.Create(form);
      scrollbox.BorderStyle:= bsNone;
      scrollbox.Color:= clWhite;
      scrollbox.Parent:= groupbox[1];
      scrollbox.SetBounds(5, 15, 320, 230);
      for i:= 0 to 4 do
      begin
        lbledits[i]:= TLabeledEdit.Create(form);
        lbledits[i].Parent:= groupbox[0];
        if(i > 0)then
        begin
          lbledits[i].SetBounds(45, 32 + i * 39, 30, 21);
          lbledits[i].Text:= '10';
        end else
          lbledits[i].SetBounds(5, 30, 119, 21);
        lbledits[i].EditLabel.Caption:= TSA[i];
      end;
      lbledits[0].Text:= 'perfectBand'
      SetArrayLength(TSA, 0);
      button:= TButton.Create(form);
      button.Parent:= groupbox[0];
      button.Caption:= 'Add';
      button.SetBounds(5, 215, 119, 28);
      button.OnClick:= @add;
      for i:= Low(labels) to High(labels) do
        for i2:= Low(labels[i]) to High(labels[i]) do
        begin
          labels[i][i2]:= TLabel.Create(form);
          labels[i][i2].Parent:= scrollbox;
          case i of
            0: begin
                 labels[0][i2].Font.Color:= clBlue;
                 labels[0][i2].SetBounds(5, 5 + (i2 - 1) * 15, 21, 15);
                 labels[0][i2].Caption:= IntToStr(i2) + '.';
               end;
            1: begin
                 labels[1][i2].Font.Color:= clRed;
                 labels[1][i2].SetBounds(labels[0][i2].Left + (labels[0][i2].Width + 5), labels[0][i2].Top, 21, 15);
               end;
          end;
        end;
      Result:= (form.ShowModal = mrOK);
    end;

    function loadForm: Variant;
    var
      v: TVariantArray;
    begin
      SetArrayLength(v, 0);
      Result:= ThreadSafeCall('buildForm', v);
    end;

    begin
      try
        loadForm;
      except
      finally
        FreeForm(form);
      end;
    end.
    ..that you are trying to build?

    If it is... Maybe you could use that for finding solutions to your project?
    If it is not... You could try posting your script here, as it is kinda hard to help having only small parts of it..

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Just a quick question? Did I say quick?
    By SeanJohn in forum OSR Help
    Replies: 3
    Last Post: 01-28-2009, 12:03 AM
  2. Need help quick
    By Zeta in forum OSR Help
    Replies: 11
    Last Post: 10-29-2007, 06:14 AM

Posting Permissions

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