Results 1 to 2 of 2

Thread: Problem with Scar form

  1. #1
    Join Date
    Dec 2009
    Location
    Newcastle, Australia
    Posts
    888
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Problem with Scar form

    SCAR Code:
    program New;
    var
      VoteNoForm: TForm;
      VoteNumber: TComboBox;
      OkBtn, CancelBtn: TButton;

    procedure InitVoteNoForm;
    begin
      VoteNoForm := CreateForm;
      VoteNoForm.Left := 200;
      VoteNoForm.Top := 160;
      VoteNoForm.Width := 220;
      VoteNoForm.Height := 110;
      VoteNoForm.Caption := 'Rum Rebellion';
      VoteNoForm.Color := ClWhite;
     
      VoteNumber := TComboBox.Create(VoteNoForm);
      VoteNumber.Parent := VoteNoForm;
      VoteNumber.Top := 10;
      VoteNumber.Left := 10;
      VoteNumber.Width := 180;
      VoteNumber.Height := 20;
      VoteNumber.TEXT := '1';

      OkBtn := TButton.Create(VoteNoForm);
      OkBtn.Parent := VoteNoForm;
      OkBtn.Caption := 'OK';
      OkBtn.Top := 40;
      OkBtn.Left := 10;
      OkBtn.Height := 30;
      OkBtn.Width := 80;

      CancelBtn := TButton.Create(VoteNoForm);
      CancelBtn.Parent := VoteNoForm;
      CancelBtn.Caption := 'Cancel';
      CancelBtn.Top := 40;
      CancelBtn.Left := 110;
      CancelBtn.Height := 30;
      CancelBtn.Width := 80;
    end;

    procedure SafeInitVoteNoForm;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('InitVoteNoForm', v);
    end;

    procedure ShowVoteNoFormModal;
    begin
      VoteNoForm.ShowModal;
    end;

    procedure SafeShowVoteNoFormModal;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('ShowVoteNoFormModal', v);
    end;

    Function BuyVoteMultiForm(HowMany: Integer): Integer;
    var
      I: Integer;
    begin
      SafeInitVoteNoForm;
      For I := 1 to HowMany do
        VoteNumber.Items.Add(IntToStr(I));
      SafeShowVoteNoFormModal;
    end;

    begin
      BuyVoteMultiForm(4);
    end.

    It runs OK, and crashes during ShafeShowVoteNoFormModal. however if i remove the
    SCAR Code:
    For I := 1 to HowMany do
        VoteNumber.Items.Add(IntToStr(I));
    lines it runs without a problem

    Edit: Right, sick of this happening, I post, 5 seconds later, I think of something and it fixes it...

    I added
    VoteNumber.Items.Add('1');
    in InitForm, it solves the problem (obviously I have to change other parts) but scar doesn't crash...
    Last edited by Bad Boy JH; 08-23-2010 at 11:26 AM.

    Current Script Project
    Pot of flour gatherer - 95% done

    Can't get Simba to work? Click here for a tutorial

  2. #2
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    You need to synchronize all access to VCL components because they run in the main thread, not just the creation of the form, this will work:
    SCAR Code:
    program New;
    var
      VoteNoForm: TForm;
      VoteNumber: TComboBox;
      OkBtn, CancelBtn: TButton;

    procedure InitVoteNoForm;
    begin
      VoteNoForm := CreateForm;
      VoteNoForm.Left := 200;
      VoteNoForm.Top := 160;
      VoteNoForm.Width := 220;
      VoteNoForm.Height := 110;
      VoteNoForm.Caption := 'Rum Rebellion';
      VoteNoForm.Color := ClWhite;

      VoteNumber := TComboBox.Create(VoteNoForm);
      VoteNumber.Parent := VoteNoForm;
      VoteNumber.Top := 10;
      VoteNumber.Left := 10;
      VoteNumber.Width := 180;
      VoteNumber.Height := 20;
      VoteNumber.TEXT := '1';

      OkBtn := TButton.Create(VoteNoForm);
      OkBtn.Parent := VoteNoForm;
      OkBtn.Caption := 'OK';
      OkBtn.Top := 40;
      OkBtn.Left := 10;
      OkBtn.Height := 30;
      OkBtn.Width := 80;

      CancelBtn := TButton.Create(VoteNoForm);
      CancelBtn.Parent := VoteNoForm;
      CancelBtn.Caption := 'Cancel';
      CancelBtn.Top := 40;
      CancelBtn.Left := 110;
      CancelBtn.Height := 30;
      CancelBtn.Width := 80;
    end;

    procedure SafeInitVoteNoForm;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('InitVoteNoForm', v);
    end;

    procedure ShowVoteNoFormModal;
    begin
      VoteNoForm.ShowModal;
    end;

    procedure SafeShowVoteNoFormModal;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('ShowVoteNoFormModal', v);
    end;

    procedure AddLine(s: string);
    begin
      if Assigned(VoteNumber) then
        VoteNumber.Items.Add(s);
    end;

    procedure SafeAddLine(s: string);
    var
      v: TVariantArray;
    begin
      setarraylength(v, 1);
      v[0] := s;
      ThreadSafeCall('AddLine', v);
    end;

    Function BuyVoteMultiForm(HowMany: Integer): Integer;
    var
      I: Integer;
    begin
      SafeInitVoteNoForm;
      for I := 1 to HowMany do
        SafeAddLine(IntToStr(I));
      SafeShowVoteNoFormModal;
    end;

    begin
      BuyVoteMultiForm(4);
    end.

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
  •