Solved

About Box & random values

Posted on 2000-04-24
12
142 Views
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.

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

0
Comment
Question by:Ben_iti
  • 7
  • 4
12 Comments
 
LVL 15

Accepted Solution

by:
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}
var
  SplashScreen : TSplashScreen;  {in the Splash unit}
begin
try
SplashScreen := TSplashScreen.Create(Application);
  SplashScreen.Show;
  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
  }
 SplashScreen.Close;
finally  {Make sure the splash screen gets released}
  SplashScreen.Free;
end;  
Application.Run;

end.



For the other random values:

Randomize;
X := Random(5);

( Only call Randomize once in your entire application);

Yours,

Alex
0
 

Author Comment

by:Ben_iti
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

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
0
 

Author Comment

by:Ben_iti
ID: 2746207
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
0
 
LVL 15

Expert Comment

by:simonet
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);
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


0
 

Author Comment

by:Ben_iti
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

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





0
 
LVL 15

Expert Comment

by:simonet
ID: 2747428
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
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Ben_iti
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

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





0
 
LVL 15

Expert Comment

by:simonet
ID: 2751555
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
0
 

Author Comment

by:Ben_iti
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.

Thanks

Ben
0
 
LVL 3

Expert Comment

by:darinw
ID: 2900203
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
0
 

Author Comment

by:Ben_iti
ID: 2930963
Answer accepted
0
 

Author Comment

by:Ben_iti
ID: 2930964
Sorry about taking so long

Ben

Ben
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now