About Box & random values

Hello there

How do I include an aboutbox to load up before my main app
similar to Adobe photoshop how it shows the registrator and company owner.

How do I do that?

Ive opened a unit2.pas and my main app uses it. ive also included in my main app to use unit2.pas as well
ive also included my unit2.pas (form2) in my main app project file.

the thing is even though I have all files linked
when it comes to executing the file
the main app opens first and not the about box, and im wondering why
My helpfile no longers loads anymore cos the helpfiles were shifted.


how do I go about letting a app choose random assigned variables.

My helpfile I had earlier did not document it.

please reply



Who is Participating?
What you're looking for is a "splash screen".

The best place to open a splash screen is in the project source  file after the first FormCreate and before the Run  This is  accomplished by creating a form on the fly and then displaying it before the app is actual opened.

 program Project1;

uses Forms,  Unit1 in 'UNIT1.PAS' {Form1}, Splash;

{$R *.RES}
  SplashScreen : TSplashScreen;  {in the Splash unit}
SplashScreen := TSplashScreen.Create(Application);
  SplashScreen.update; {To paint the splash screen}
  Application.CreateForm(TForm1, Form1);
   do other CreatForms or any other processing

   before the app is to be opened
finally  {Make sure the splash screen gets released}


For the other random values:

X := Random(5);

( Only call Randomize once in your entire application);


Ben_itiAuthor Commented:
Hello Alex

I am using Delphi 2.0
and the code you gave me isnt compatible with my version of delphi
maybe I should off mentioned that.

But anyway, I did some changes to the code
like where it says 'SplashScreen'
I had to change it to 'SplashForm'
and such and such
ok my project then loads splash.pas

Ok, my status, is that it opens a aboutbox but then it freezes and crashes

here is the code extract


  SplashForm := TSplashForm.Create(Application);
  SplashForm.update; {To paint the splash screen}
  Application.Title := 'Bens Application';
  Application.CreateForm(TForm1, Form1);
  finally  {Make sure the splash form gets released}

How does the Splashscreen normally work?
Is there time counter for the splashscreen to close after so many seconds before opening main app
or does it require user activity? as I noticed that it is a clickable panel.
The variable you declared for me comes up as a error when its declare in the project file saying that it already exists, then I checked my Splash.pas and it is already declared.

Also for the Randomize
I do not gather much from your help
as I need to Randomize more than once
so i'll have three to four randomizes throughout my app.

What does the following code mean?

X := Random(5);

( Only call Randomize once in your entire application);
If I can only call Randomize once
how would I go about using it
to call other random variables other than the one X?

Please reply

Ben_itiAuthor Commented:

Ignore my problem with the splashscreen
It actually works

My problem was that I kept on loading in Delphi instead of on its own
so yes, the splashform part is working thanks

But I still need help on the Randomize
Please refer to previous message


Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Ok, Ben, I'll elaborate a little more on generating random values.

Part I - The Randomize function
Randomize initializes the built-in random number generator with a random value (obtained from the system clock). The random number generator should be initialized by making a call to Randomize.

In most cases, you should not call Randomize more than once in your application, since the generator's seed is application-wide. The only case where you should call Randomize more han once is when you need several IDENTICAL series of random numbers (= when you need to repeat the same series that has already been generated). This is more common in cryptographic situatios.

I usually place the Randomize function in the OnCreate event of the main form:

procedure TFrmMain.Create(Sender : TObject);

That's it.

Part II - Generating Random numbers
For generating random numbers, we use the Random() function, whose description is:

Random returns a random number within the range 0 <= X < Range. If Range is not specified, the result is a real-type random number within the range 0 <= X < 1.

The first thing you need to know is what is the interval of the numbers you need. Once that's set, everything is a breeze. Here are several examples:

  Rndf : double;
  Rndi : integer;

a) A Random (float) number between 0 and 1
Rndf := Random;

b) A random (int) number between 0 and 100;
Rndi := trunc(Random * 101)
Rndi := Trunc(Random(100));

c) 50 random numbers (float) between 5 and 15
for i := 0 to 49 do
  Rndf := Random * 16 + 5;

I guess that pretty much covers all the basics. If you need any further help/explanation, just let me know, ok?



Ben_itiAuthor Commented:
Hi Alex

Random numbers is not what I need
I need Random assigned variables
how do I get those variables to jump around?

say for example


Hello := #$3A+#$4B;
Goodbye := #$2C+#$7A;
Goaway := #$6F+#$00;


Random (Hello,Goodbye,Goaway);

// Randomly choose 1 out of the 3 //
then somehow write it on to file called


How do I get it to randomly choose out of the three entries I have listed there

Hello, Goodbye, Go away?
and how would I get it to fit in with the writein(f,?????);

although I might be able to figure that one out myself, any hints?

Please reply



First of all, the random numbers generation tip I gave you will be necessary here, so don't forget how to do it.

The function below will take a variable number of parameters and return a randomly chosen value from the parameters.

function RandomVarVal(x : array of Variant) : Variant
  Rnd : integer;
  Rnd := Trunc(Random * (High(x) + 1));
  Result := x[Rnd];

Here's an example of how to use it:
v1 := RandomVarVal([Hello, GoodBye, GoAway]);
v2 := RandomVarVal([Hello, GoodBye, GoAway, Stay, SpeakUp, SayNoMore]);

Note that parameters are enclosed in brackets "[  ]" and that you can pass it as many parameters as you want.

If you wish you can change the parameter types (from the parameters and the result) from VARIANT to whatever you need. I wrote it as Variant because then it's an all-purpose function.


Ben_itiAuthor Commented:
Hi there Alex

Now that we have it
I need further explanation on what it does.

It doesnt help me much to just think of it as a piece of code, it helps me more to know what does what.

from what I gather

I understand that 'names' or 'items' enclosed in brackets are the variables that will be randomly chosen at once.

I also understand that RandomVarVal and its following lines of code make up the function.

What I dont understand is
that to execute it

I must use
v1 := RandomVarVal([Hello,Goodbye,GoAway]);

What does the v1 and v2 mean?
and where does v1 and v2 fit in?

Cant I just go


Right now I assume that in the end, the v1 and v2 will hold the randomly chosen result.

Am I right?

or is it inside the variable 'x' or variable 'results'?

Please tell me where the results are stored and how the formula works
as I do not know anything about

Many thanks



The RandomVarVal function is all you need. It's already done and you don't need to change it. You pass it several variables - enclosed in brackets - each of them already containing a its own value.

Internally, what the function does is receive all the variables inside an array. Then it picks a random number based on the number of items (variables) in the array. This random number is then the position of the variable inside the array.

When you use the function, it returns the value of the randomly chosen Variable (among the serveral variables you passed to it). Therefore you must save the value returned by RandomVarVal somewhere. That's why I used "v1" (call it whatever you want).

>Right now I assume that in the end, the v1 and v2 will hold the randomly
>chosen result.

Exactly! YOu can call V1 and V2 whatever you like.

I hope this has cleared things up.

Ben_itiAuthor Commented:
Hi there Alex

Im going to be away from here
to do the coding
adding the information you gave me to the code and it may take over two weeks just to get the code working
cos i'll be busy with a competition coming up, but dont get the feeling that I wont reply cos I will

I should be back in two weeks time
with a reply to the answers.


Reviewing question.

Ben_iti, after all the assistance you have gotten, you need to come back and accept an A grade answer :-)

Customer Service
Ben_itiAuthor Commented:
Answer accepted
Ben_itiAuthor Commented:
Sorry about taking so long


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.