Link to home
Start Free TrialLog in
Avatar of Ben_iti
Ben_iti

asked on

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.

Also

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

My helpfile I had earlier did not document it.

please reply

Thanks

Ben

ASKER CERTIFIED SOLUTION
Avatar of simonet
simonet
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ben_iti
Ben_iti

ASKER

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

begin

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

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?

Randomize;
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
Avatar of Ben_iti

ASKER

Alex,

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

Thanks

Ben
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);
begin
  Randomize;
end;

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:

var
  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)
or
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?

Yours,

Alex


Avatar of Ben_iti

ASKER

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

var

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

begin

Random (Hello,Goodbye,Goaway);

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

Assignfile(f,'man.txt);
Rewrite(f);
Writein(f,random);
closefile;

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

Ben





Ok...

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
var
  Rnd : integer;
begin
  Rnd := Trunc(Random * (High(x) + 1));
  Result := x[Rnd];
end;

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.

Yours,

Alex
Avatar of Ben_iti

ASKER

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

RandomVarVal([Hello,Goodbye,GoAway]);  

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
Randomizing.

Many thanks

Ben





Ok...

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.

Alex
Avatar of Ben_iti

ASKER

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.

Thanks

Ben
Reviewing question.

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

darinw
Customer Service
Avatar of Ben_iti

ASKER

Answer accepted
Avatar of Ben_iti

ASKER

Sorry about taking so long

Ben

Ben