Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

procedure declarations 3

Status
Not open for further replies.

dik

Technical User
Jul 18, 2001
217
MD
I'm doing a little programming in Delphi, having been away from it for 15 years or more, and, I'm having a problem. It has to do with the location and declaration of procedures within a form. the procedures are loaded when the form is created. The basic source, reduced for size is below: I've spent all day and end up with from 7 to 40 compile errors.
Does anyone see anything obviously out of whack with the placement or declaration of the procedures? and can anyone suggest why the Case faults on ItemIndex 2?

Thanks, Dik
--------------------------------- Begin Code -------------------------------------------

unit Main_Screen;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
TMain_ScreenF = class(TForm)
Question: TLabel;
Answer: TEdit;
Continue: TButton;
About: TButton;
Main_Screen: TLabel;

procedure FormCreate(Sender: TObject);
procedure AboutClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure AddRand(add1:integer; add2:integer ;sum:integer);
procedure SubRand (minu:integer; subt:integer; diff:integer);
procedure MulRand (mulp:integer; mull:integer; prod:integer);
procedure DivRand (divd:integer; divs:integer; quo:integer);
procedure EqualRand (num1:integer; num2:integer; eqal:integer; logi:integer);

I get compile errors no matter where I place these


private
{ Private declarations }
public
{ Public declarations }
end;

var
Main_ScreenF: TMain_ScreenF;
maxadd, maxsub, maxmul, maxdiv, maxans: integer;
dummy: string;
config: TextFile;
These are global variables


implementation

{$R *.DFM}

uses
Practice, About, Configuration;

var
add1, add2, sum, minu, subt, diff, mulp, mull, prod, divd, divs, quo, num1, num2, eqal, logi: integer;

These are variables local to the form


procedure TMain_ScreenF.FormCreate(Sender: TObject);
begin
Left:=(Screen.Width-Width) div 2; // center form
Top:=(Screen.Height-Height) div 2;
end;



procedure TMain_ScreenF.AboutClick(Sender: TObject);
begin
AboutF.ShowModal;
end;



procedure TMain_ScreenF.FormActivate(Sender: TObject);
var
equal: string;
begin
case PracticeF.RadioGroup1.ItemIndex of
1:
Begin
Main_ScreenF.Main_Screen.Caption := 'Addition Practice';
AddRand(add1; add2; sum); The compiler faults all the procedures: [dcc32 Error] Main_Screen.pas(74): E2035 Not enough actual parameters
[dcc32 Error] Main_Screen.pas(74): E2014 Statement expected, but expression of type 'Integer' found

Question.Caption := IntToStr(add1) + ' + ' + IntToStr(Add2) + ' =';
End;
2: The compiler faults this stating '[dcc32 Error] Main_Screen.pas(77): E2003 Undeclared identifier: '2', but lets the other 1 - 8 values stand'
Begin
Main_Screen.Caption := 'Subtraction Practice';
SubRand (minu; subt; diff);
Question.Caption := IntToStr(minu) + ' - ' + IntToStr(subt) + ' =';
End;
3:
Begin
Main_Screen.Caption := 'Greater Than - Less Than Practice';
EqualRand (num1; num2; eqal; logi);

if eqal = 1 then
equal := ' < '
else if eqal = 2 then
equal := ' = '
else if eqal = 3 then
equal := ' > ';

Question.Caption := IntToStr(num1) + equal + IntToStr(Add2);
End;
4:
Begin
Main_Screen.Caption := 'Addition and Subtraction Practice';
AddRand(add1; add2; sum);
SubRand (minu; subt; diff);
Question.Caption := IntToStr(add1) + ' + ' + IntToStr(Add2) + ' =';
Question.Caption := IntToStr(minu) + ' - ' + IntToStr(subt) + ' =';
End;
5:Begin
Main_Screen.Caption := 'Multiplication Practice'
MulRand (mulp; mull; prod);
Question.Caption := IntToStr(mulp) + ' X ' + IntToStr(mull) + ' =';
6:Begin
Main_Screen.Caption := 'Division Practice'
DivRand (divd; divs; quo);
Question.Caption := IntToStr(divd) + ' / ' + IntToStr(divs) + ' =';
7:Begin
Main_Screen.Caption := 'Multiplication and Division Practice'
MulRand (mulp; mull; prod);
Question.Caption := IntToStr(mulp) + ' X ' + IntToStr(mull) + ' =';
DivRand (divd; divs; quo);
Question.Caption := IntToStr(divd) + ' / ' + IntToStr(divs) + ' =';
End;
8:Begin
Main_Screen.Caption := 'Completely Mixed Combinations Practice'
AddRand(add1; add2; sum);
Question.Caption := IntToStr(add1) + ' + ' + IntToStr(Add2) + ' =';
SubRand (minu; subt; diff);
Question.Caption := IntToStr(minu) + ' - ' + IntToStr(subt) + ' =';
MulRand (mulp; mull; prod);
Question.Caption := IntToStr(mulp) + ' X ' + IntToStr(mull) + ' =';
DivRand (divd; divs; quo);
Question.Caption := IntToStr(divd) + ' / ' + IntToStr(divs) + ' =';

EqualRand (num1; num2; eqal; logi);

if eqal := 1 then
equal := ' < ';
else if eqal := 2 then
equal := ' = ';
else if eqal := 3 then
equal := ' > ';

Question.Caption := IntToStr(num1) + equal + IntToStr(Add2);
End;
End;



//** procedure AddRand ********************************************************
//
// Procedure determines two addends and provides the sum. The addends are
// individually less than the value maxadd and the sum is less than the
// value maxans%. These values are passed to the procedure by a COMMON
// SHARED statement.
//
// PARAMETERS: add1 = first addend
// add2 = second addend
// sum = sum of addends
//
procedure AddRand(add1:integer; add2:integer; sum:integer);
begin
randomize;
add1 := Random(maxadd + 1);

WHILE (sum > maxans) do
begin
add2 := Random(maxadd + 1);
sum := add1 + add2;
end;
end; This is a typical procedure...



//** procedure SubRand ********************************************************
//
// Procedure determines two numbers and provides the diference. The numbers
// are individually less than the value maxsub% and the difference is less
// than the value maxans%. These values are passed to the procedure by a
// COMMON SHARED statement.
//
// PARAMETERS: minu = minuend
// subt = subtrahend
// diff = minuend - subtrahend
//
procedure SubRand (minu:integer; subt:integer; diff:integer);
begin
randomize;

While subt > minu do
begin
minu := Random(maxsub + 1);
subt := Random(maxsub + 1);
diff := minu - subt;
end;
end;



//** procedure MulRand *******************************************************
//
// Procedure determines two numbers and provides the product. The numbers
// are individually less than the value maxmul% and the product is less than
// the value maxans%. These values are passed to the procedure by a COMMON
// SHARED statement.
//
// PARAMETERS: mulp = multiplier
// mull = multiplicand
// prod = product
//
procedure MulRand (mulp:integer; mull:integer; prod:integer);
Begin
randomize;
mull := Random(maxmul + 1);

While prod > maxans do
begin
mulp := Random(maxmul + 1);
prod := mull * mulp;
end;
end;



//** procedure DivRand *******************************************************
//
// Procedure determines a dividend and a divisor and provides the quotient.
// The numbers are individually less than the value maxdiv% and the quotient
// is not bounded, but with a normal value of maxdiv%, it is likely less
// than the value maxans%. These values are passed to the procedure by a
// COMMON SHARED statement.
//
// PARAMETERS:
// divd = dividend
// divs = divisor
// quo = quotient
//
procedure DivRand (divd:integer; divs:integer; quo:integer);
Begin
randomize;
quo := Random(maxdiv + 1);

While ((quo > maxdiv) OR (divs = 0)) do
begin
divs := Random(maxdiv + 1);
divd := quo * divs; // divd, divs, and quo are integers
end;
End;



//** procedure EqualRand ******************************************************
//
// Procedure randomly generates two numbers and determines the logical
// comparison between them using a random generated comparison. It returns
// two numbers, the equality sysbol, and and a logical true or false for the
// values generated. The maximum values are passed to the procedure by being
// in scope.
//
// PARAMETERS: num1 = first number
// num2 = Second number
// eqal = Random equality sysbol
// 1 denotes <
// 2 denotes =
// 3 denotes >
// logi = 1 denoted True
// 0 denotes False
//
procedure EqualRand (num1:integer; num2:integer; eqal:integer; logi:integer);
Begin
randomize;

num1 := Random(maxadd + 1);
num2 := Random(maxadd + 1);
eqal := Random(4);

if (num1 - num2) < 0 then
begin
logi := 1;
end
else if (num1 - num2) = 0 then
begin
logi := 2;
end
else if (num1 - num2) > 0 then
begin
logi := 3;
end;
end;

end.
 
Hi dik,

You problem seems to be a syntax error how you call the procedure.

You declare your procedure
Code:
procedure AddRand(add1:integer; add2:integer; sum:integer);
begin
  ...
end;

and you call it in the case statement as
Code:
case PracticeF.RadioGroup1.ItemIndex of
  ...    
     [highlight #EF2929]AddRand(add1; add2; sum);[/highlight]
But it should be instead
Code:
case PracticeF.RadioGroup1.ItemIndex of
  ...    
     [highlight #8AE234]AddRand(add1, add2, sum);[/highlight]

In declaration the several argument types are separated by semicolon = ";", but in calling the parameters are separated by comma = ","

Btw if all arguments in your procedure are of the same type, you can declare it as
Code:
procedure AddRand(add1, add2, sum :integer);
begin
  ...
end;
 
Thanks, we'll give it a try...

Dik
 
I've made the modifications... it makes the code more clear and easier to follow, thanks.

I still have some hiccups and this occurs with all procedures. I've attached a partial copy with the mods, and also the compiler error messages. I have the same messages for each procedure... so, it's something fundamentally wrong. The procedures are located in the form procedure: TMain_ScreenF.FormActivate(Sender: TObject);

unit Main_Screen;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
TMain_ScreenF = class(TForm)
Question: TLabel;
Answer: TEdit;
Continue: TButton;
About: TButton;
Main_Screen: TLabel;

procedure FormCreate(Sender: TObject);
procedure AboutClick(Sender: TObject);
procedure FormActivate(Sender: TObject);

procedure AddRand(add1, add2, sum: integer);
procedure SubRand (minu, subt, diff: integer);
procedure MulRand (mulp, mull, prod: integer);
procedure DivRand (divd, divs, quo: integer);
procedure EqualRand (num1, num2, eqal, logi: integer);

<Code>

case PracticeF.RadioGroup1.ItemIndex of
1:
Begin
Main_ScreenF.Main_Screen.Caption := 'Addition Practice';
AddRand(add1, add2, sum);
Question.Caption := IntToStr(add1) + ' + ' + IntToStr(Add2) + ' =';
End;

<Code>

//** procedure AddRand ********************************************************
//
// Procedure determines two addends and provides the sum. The addends are
// individually less than the value maxadd and the sum is less than the
// value maxans%. These values are passed to the procedure by a COMMON
// SHARED statement.
//
// PARAMETERS: add1 = first addend
// add2 = second addend
// sum = sum of addends
//
procedure AddRand(add1, add2, sum: integer);
begin
randomize;
add1 := Random(maxadd + 1);

WHILE (sum > maxans) do
begin
add2 := Random(maxadd + 1);
sum := add1 + add2;
end;
end;

<Error Messages for all procedures>
[dcc32 Error] Main_Screen.pas(163): E2070 Unknown directive: 'AddRand'
[dcc32 Error] Main_Screen.pas(21): E2065 Unsatisfied forward or external declaration: 'TMain_ScreenF.AddRand'

 
I have the same messages for each procedure... so, it's something fundamentally wrong.
[highlight #FCE94F]The procedures are located in the form procedure: TMain_ScreenF.FormActivate(Sender: TObject)[/highlight]
My question: And when you place them in the same unit as you had before (i.e. in the unit Main_Screen), then it works or not ?
I asked, because I thing that the error messages:
[pre]
E2070 Unknown directive: 'AddRand'
E2065 Unsatisfied forward or external declaration: 'TMain_ScreenF.AddRand'[/pre]
say that the compiler cannot find the procedures.

 
The basic layout worked prior to adding the procedures; they were modified from a basic program I wrote 30 years ago and was updating it, in Windows, for my grandson. They were modified and cut and pasted into Delphi. I couldn't find a method to add new procedures into a program.

Dik
 
Unfortunately, I probably can not help you further, because I have zero experience with Delphi. Similar to you, I worked decades ago with Turbo Pascal (1989-1995) and then later I tried GNU Pascal and Free Pascal... but Delphi I never had installed.

To solve your issues, you can google for the error messages.
For example there are many posts to your second error message on StackOverflow, you may ask there to get the answer:
 
Thanks, I'll try that. I was checking the error messages on Embarcadero and found their description next to useless.

Dik
 
you are adding your own Private/Public methods/variables to the section of the Form's declaration reserved for Delphi maintained methods/variables. Your own methods need to be added to either the Private Section (if no other object other than the form need access to the methods, or to the Public section where these methods would be available to other objects.
Code:
type
  TMain_ScreenF = class(TForm)
    Question: TLabel;
    Answer: TEdit;
    Continue: TButton;
    About: TButton;
    Main_Screen: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure AboutClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    procedure AddRand(add1:integer; add2:integer ;sum:integer);
    procedure SubRand (minu:integer; subt:integer; diff:integer);
    procedure MulRand (mulp:integer; mull:integer; prod:integer);
    procedure DivRand (divd:integer; divs:integer; quo:integer);
    procedure EqualRand (num1:integer; num2:integer; eqal:integer; logi:integer);
  public
    { Public declarations }
end;
 
Additionally, you are not identifying that the methods are part of the form. Check the difference between how Delphi maintained methods are declared vs yours.

yours:
Code:
procedure AddRand(add1, add2, sum: integer);
....


Delphi Managed:
Code:
procedure [i]TMain_ScreenF[/i].FormActivate(Sender: TObject);
....
Your methods must start with "TMain_ScreenF."

Code:
procedure TMain_ScreenF.AddRand(add1, add2, sum: integer);
....
 
If you are still having issues, please attach your updated code, so we can work out any additional issues. BTW: One more thing I noticed. This next line:

Code:
Main_ScreenF.Main_Screen.Caption := 'Addition Practice';

You should never refer to your form by name (Main_ScreenF.~~~) within the form itself. In this instance you would simply need to do:

Code:
Main_Screen.Caption := '...';

but IF you do end up needing to refer to the form object in your code, there is a special variable that is available called "SELF". So you would use

Code:
Self.Main_Screen.Caption := '...';
 
Thanks Majlumbo... I'll give that a try and let you know... I've been away from programming for a couple of decades... and slowly getting back. Porting a program written in MS BASIC PDS 7.2 to delphi for my yougest grandchild. With earlier Delphi 5, I used to name the form the same as the unit with an 'F' postscript. I never wrote anything serious enough that would force it to 'break'. I'll get out of that habit.

I have a few BASIC programs with over a meg in source code... used to use BASIC in lieu of C because, at the time, BASIC used the MS Fortran math library which was significantly faster then the C, math library.

again, thanks... Dik
 
@dik,
When it was originally in Basic, you could use rather a free basic compiler like or or the newest MS free basic for kids .
When I first saw this SmallBasic, I thought It's right tool to learn my son basics of programming, but they use in the school Logo so I was forced to change to it :).
If you need a Pascal Programming Language, then Free Pascal ( and Lazarus ( are free.
 
Thanks mikrom... I had started to, and then decided to see if I could do it in Delphi... In BASIC, when I first wrote it, I had to save the font table, rewrite it so the numbers would be 2" high, and then restore it... It was a challenge in the Pre-Windows era... I was quite active on the Fidonet BASIC conference, back then...

Dik
 
I put a lot of notes within your code. Please read through them, but it's hard to convey all the items you need to work on this way, so feel free to ask questions anywhere you don't understand.
Code:
unit Main_Screen;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TMain_ScreenF = class(TForm)
    Question: TLabel;
    Answer: TEdit;
    Continue: TButton;
    About: TButton;
    BitBtn1: TBitBtn;//add this
    Main_Screen: TLabel;
    Exit: TButton;

    procedure FormCreate(Sender: TObject);
    procedure AboutClick(Sender: TObject);
   // procedure FormActivate(Sender: TObject);//remove reference to this....
    //add a bitbtn to your form and add OnClick method
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
    add1: integer;
    add2: integer;
    sum: integer;
    minu: integer;
    subt: integer;
    diff: integer;
    mulp: integer;
    mull: integer;
    prod: integer;
    divd: integer;
    divs: integer;
    quo: integer;
    num1: integer;
    num2: integer;
    eqal: integer;
    logi: integer;
    procedure AddRand(var add1, add2, sum: integer);
    procedure SubRand(var minu, subt, diff: integer);
    procedure MulRand(var mulp, mull, prod: integer);
    procedure DivRand(var divd, divs, quo: integer);
    procedure EqualRand(var num1, num2, eqal, logi: integer);
    procedure RunCycle;
  public
    { Public declarations }
var
  Main_ScreenF: TMain_ScreenF;
  maxadd, maxsub, maxmul, maxdiv, maxans: integer;
  dummy: string;
  config: TextFile;
end;

implementation

{$R *.DFM}

uses
  Practice, About, Configuration;

procedure TMain_ScreenF.FormCreate(Sender: TObject);
begin
  Left:=(Screen.Width-Width)  div 2;//This does NOT center the screen, it puts the TOP / LEFT corner in the center
  Top:=(Screen.Height-Height) div 2;//Also Screen.Width & Height may not be what you want if you have
                                    //more than one monitor....
end;

//Add method

procedure TMain_ScreenF.BitBtn1Click(Sender: TObject);
begin
  RunCyle;
end;


procedure TMain_ScreenF.AboutClick(Sender: TObject);
begin
  AboutF.ShowModal;
end;

//FormActivate does NOT seem appropriate for what you are doing here.  Form Activate is triggered EVERYTIME AND ONLY when your form
//becomes active.  i.e. you click on another program then click on this program again.
//are you intending that this procedure only happen once when program starts? - then use OnCreate (FORMCREATE Method) or if you want it 
//to run after say a button click, then make this one of your private methods (change it's name and delete the 
//reference to OnActivate) and call that method from the buttonclick method.


//AddRand, SubRand etc, seems that they should actually be functions that return a value, written as they are
//they DO NOTHING.  You pass the values (e.g. add1, add2 and sum in AddRand) by VALUE not by REFERENCE, so any 
//manipulation that is happening in the procedure IS LOST when it returns, so when you try to set Question.Caption
//it won't work since any value set to add1 and add2 has been lost.

//you need to declar your procedures like so
//procedure AddRand(var add1, add2, sum: integer);//adding var 



procedure TMain_ScreenF.RunCyle;//Changed to RUNCYCLE
var
  start_time, end_time: TDateTime;
  equal: string;
begin
  start_time := Now;
  

  //WHAT is PRACTICEF? another form?
  //if so you don't want to access the Radiogroup1 componnet 
  //directly
  //MAKE A PUBLIC function on that form that
  //returns the value of the radiogroup1's itemindex and call
  //the function instead...

  case PracticeF.RadioGroup1.ItemIndex of
    1:
      Begin
        Main_Screen.Caption := 'Addition Practice';
        AddRand(add1, add2, sum); 
        Question.Caption := IntToStr(add1) + ' + ' + IntToStr(Add2) + ' =';
      End;
    2:
      Begin
        Main_Screen.Caption := 'Subtraction Practice';
        SubRand (minu, subt, diff);
        Question.Caption := IntToStr(minu) + ' - ' + IntToStr(subt) + ' =';
      End;
    3:
      Begin
        Main_Screen.Caption := 'Greater Than - Less Than Practice';
        EqualRand (num1, num2, eqal, logi);

        if eqal = 1 then
          equal := ' < '
        else if eqal = 2 then
          equal := ' = '
        else if eqal = 3 then
          equal := ' > ';

        Question.Caption := IntToStr(num1) + equal + IntToStr(Add2);
      End;
    4:
      Begin
        Main_Screen.Caption := 'Addition and Subtraction Practice';
        AddRand(add1, add2, sum);
        SubRand (minu, subt, diff);
        Question.Caption := IntToStr(add1) + ' + ' + IntToStr(Add2) + ' =';
        Question.Caption := IntToStr(minu) + ' - ' + IntToStr(subt) + ' =';
      End;
    5:
      Begin
        Main_Screen.Caption := 'Multiplication Practice';
        MulRand (mulp, mull, prod);
        Question.Caption := IntToStr(mulp) + ' X ' + IntToStr(mull) + ' =';
      End;
    6:
      Begin
        Main_Screen.Caption := 'Division Practice';
        DivRand (divd, divs, quo);
        Question.Caption := IntToStr(divd) + ' / ' + IntToStr(divs) + ' =';
      End;
    7:
      Begin
        Main_Screen.Caption := 'Multiplication and Division Practice';
        MulRand (mulp, mull, prod);
        Question.Caption := IntToStr(mulp) + ' X ' + IntToStr(mull) + ' =';
        DivRand (divd, divs, quo);
        Question.Caption := IntToStr(divd) + ' / ' + IntToStr(divs) + ' =';
      End;
    8:
      Begin
        Main_Screen.Caption := 'Completely Mixed Combinations Practice';
        AddRand(add1, add2, sum);
        Question.Caption := IntToStr(add1) + ' + ' + IntToStr(Add2) + ' =';
        SubRand (minu, subt, diff);
        Question.Caption := IntToStr(minu) + ' - ' + IntToStr(subt) + ' =';
        MulRand (mulp, mull, prod);
        Question.Caption := IntToStr(mulp) + ' X ' + IntToStr(mull) + ' =';
        DivRand (divd, divs, quo);
        Question.Caption := IntToStr(divd) + ' / ' + IntToStr(divs) + ' =';

        EqualRand (num1, num2, eqal, logi);

        if eqal = 1 then
          equal := ' < '
        else if eqal = 2 then
          equal := ' = '
        else if eqal = 3 then
          equal := ' > ';

        Question.Caption := IntToStr(num1) + equal + IntToStr(Add2);
      End;
End;



//** procedure AddRand ********************************************************
//
// Procedure determines two addends and provides the sum. The addends are
// individually less than the value maxadd and the sum is less than the
// value maxans. These values are passed to the procedure by being global
// in scope.
//
// PARAMETERS: add1 = first addend
//             add2 = second addend
//             sum = sum of addends
//
//procedure TMain_ScreenF.AddRand(add1, add2, sum: integer);
//change
procedure TMain_ScreenF.AddRand(var add1, add2, sum: integer);

begin
  randomize;//you should only call randomize JUST once in a program....
            //NEVER call it more than once
  //WHERE does MAXADD get initialized????
  //if it doesn't get an initial value
  //then how do you add 1 to it???

  add1 := Random(maxadd + 1);


  //WHERE does MAXANS get initialized???
  //if it doesn't get an initial value
  //then how can you compare it to SUM???
  WHILE (sum > maxans) do
    begin
     add2 := Random(maxadd + 1);
     sum := add1 + add2;
   end;
end;



//** procedure SubRand ********************************************************
//
// Procedure determines two numbers and provides the diference. The numbers
// are individually less than the value maxsub and the difference is less
// than the value maxans. These values are passed to the procedure by being
// global in scope.
//
// PARAMETERS: minu = minuend
//             subt = subtrahend
//             diff = minuend - subtrahend
//
procedure TMain_ScreenF.SubRand (var minu, subt, diff: integer);
begin
  randomize;//you should only call randomize JUST once in a program....
            //NEVER call it more than once

	While subt > minu do
    begin
      minu := Random(maxsub + 1);
		  subt := Random(maxsub + 1);
    	diff := minu - subt;
	  end;
end;



//** procedure MulRand *******************************************************
//
// Procedure determines two numbers and provides the product. The numbers
// are individually less than the value maxmul and the product is less than
// the value maxans. These values are passed to the procedure by being global
//  in scope.
//
// PARAMETERS: mulp = multiplier
//             mull = multiplicand
//             prod = product
//
procedure TMain_ScreenF.MulRand (var mulp, mull, prod: integer);
Begin
  randomize;//you should only call randomize JUST once in a program....
            //NEVER call it more than once
  mull := Random(maxmul + 1);

  While prod  > maxans do
    begin
      mulp := Random(maxmul + 1);
      prod := mull * mulp;
    end;
end;



//** procedure DivRand *******************************************************
//
// Procedure determines a dividend and a divisor and provides the quotient.
// The numbers are individually less than the value maxdiv% and the quotient
// is not bounded, but with a normal value of maxdiv%, it is likely less
// than the value maxans. These values are passed to the procedure as global
// global in scope.
//
// PARAMETERS:
//   divd = dividend
//   divs = divisor
//   quo = quotient
//
procedure TMain_ScreenF.DivRand (var divd, divs, quo: integer);
Begin
  randomize;//you should only call randomize JUST once in a program....
            //NEVER call it more than once
  quo := Random(maxdiv + 1);

  While ((quo > maxdiv) OR (divs = 0)) do
    begin
      divs := Random(maxdiv + 1);
      divd := quo * divs;                  // divd, divs, and quo are integers
    end;
End;



//** procedure EqualRand ******************************************************
//
// Procedure randomly generates two numbers and determines the logical
// comparison between them using a random generated comparison.  It returns
// two numbers, the equality sysbol, and and a logical true or false for the
// values generated. The maximum values are passed to the procedure by being
// global in scope.
//
// PARAMETERS: num1 = first number
//             num2 = Second number
//             eqal = Random equality sysbol
//                    1 denotes <
//                    2 denotes =
//                    3 denotes >
//             logi = 1 denoted True
//                    0 denotes False
//
procedure TMain_ScreenF.EqualRand (var num1, num2, eqal, logi: integer);
Begin
  randomize;//you should only call randomize JUST once in a program....
            //NEVER call it more than once

  num1 := Random(maxadd + 1);
  num2 := Random(maxadd + 1);
  eqal := Random(4);

  if (num1 - num2) < 0 then
    begin
      logi := 1;
    end
  else if (num1 - num2) = 0 then
    begin
      logi := 2;
    end
  else if (num1 - num2) > 0 then
    begin
      logi := 3;
    end;
end;

initialize
  Randomize;//Here, it is called just once when the form is initialized
  //Maybe initialize your variables like MaxAdd, maxdiv here like:
  //MaxAdd := 12;

end.
 
I misread you "centering" code, it should center the form correctly if you have 1 monitor.
 
Thanks... the maxadd, etc. are global variables and are initialised.

I'll take a good look at your comments and modify and let you know how things work out. Thanks so much for the effort.

Dik
 
I know you've said you have been out of programming for a while, and at that time, global variables were in vogue, but global variables are now frowned upon now a days. We'll have to work on that one too sooner or later....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top