PDA

View Full Version : 2 forms in delphi 7/help with if then else



dialeyj2
07-31-2007, 03:23 PM
Hello, I'm new to Delphi and im trying to make a program with a main menu that has a few choices. When you click on the choice you want it will close the main menu form and open up the form of the choice you selected. How would you do this?

I am also having trouble with the if, then, else part of my scripts. I wrote something like this:


if image1.Picture := fileData then
image1.Picture := fileData2

The error message says "Boolean expected in script" or something like that, and it highlights that line. Please Post if you know the answer to either of these questions.

Thanks You,
daileyj2

Sp0rky
07-31-2007, 04:10 PM
You add the unit to the uses list, ie Uses Unitblabla; (on both units)

Then when you want it to show, you add to the code of your on click button:

eg



procedure TForm3.Button1Click(Sender: TObject);
begin
Form3.Hide;
Form2.Show;
end;


Hes an example:



unit UnitAbout;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls, StdCtrls, Xpman;

type
TForm3 = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Label3: TLabel;
Label4: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

Uses UnitUID;

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
Form3.Hide;
Form2.Show;
end;


Your second question:

:= means assigning something, ie x :=1 means the value 1 will be stored in the variable x.

you can say
if image1.picture = filedata then
image1.picture := filedata2

what this code does:

= meaning if image1.picture equals filedata then image1.picture is assigned to filedata2.

Hope i've helped a little.

Please post if you're still not sure what i'm on about.

dialeyj2
07-31-2007, 05:20 PM
thanks so much you really helped!!

Sp0rky
07-31-2007, 05:45 PM
No problem. Any more questions don't hesitate to ask.

dialeyj2
08-05-2007, 01:01 AM
umm... do u know how to make an edit box that only lets you type numbers if so can you also tell me how to just letters so i won't have to ask you some other time

Sp0rky
08-05-2007, 01:03 AM
In delphi I do, yes.

Want me to tell you in delphi ?

dialeyj2
08-05-2007, 01:07 AM
yes plz...wow that was fast

shaunthasheep
08-05-2007, 02:29 PM
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
numbers : string;
begin
numbers := '0123456789' + chr(8); //chr(8) is backspace.
if pos(key, numbers) = 0 then
Key := Chr(13); //changes key to enter, makes beep plus blocks it. Chr(0) can work too
end;

end.

dialeyj2
08-06-2007, 02:42 AM
um, that isn't working for me