About Box & random values

Posted on 2000-04-24
Last Modified: 2010-04-04
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



Question by:Ben_iti
  • 7
  • 4
LVL 15

Accepted Solution

simonet earned 90 total points
ID: 2743631
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);



Author Comment

ID: 2746186
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


Author Comment

ID: 2746207

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 15

Expert Comment

ID: 2746315
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?




Author Comment

ID: 2747184
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


LVL 15

Expert Comment

ID: 2747428

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.



Author Comment

ID: 2750393
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


LVL 15

Expert Comment

ID: 2751555

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.


Author Comment

ID: 2761119
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.



Expert Comment

ID: 2900203
Reviewing question.

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

Customer Service

Author Comment

ID: 2930963
Answer accepted

Author Comment

ID: 2930964
Sorry about taking so long



Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
indy Tmemory stream non latin charcter issue 2 121
Magic Software info 18 139
how to send memory stream from ics Client To ics server ? 11 139
DBCtrlGrid, Delphi, Scroll 7 26
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question