Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP!!! Form Problem

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello,

In a mdi form called "bird" I put a edit box (edit1) then
I go to uses and insert "fly".

"FLY FORM" properties:
Border Style=single
Form Style=fsNormal

The problem is when I put in the "fly" form this code:

procedure Tfly.Button1Click(Sender: TObject);
begin
bird.edit1.text:='TESTE';
end;

Accessing "BIRD" form from "FLY" gives me an error!!!

It gives me an error "Eaccessviolation"...

Could you help me solve this problem?
 

In the "BIRD" form in the "button1" I put this code:

procedure Tbird.Button1Click(Sender: TObject);
begin
Application.CreateForm(Tfly, fly);
end;

INSTEAD OF:

procedure Tbird.Button1Click(Sender: TObject);
var
fly:Tfly;
begin
fly:=Tfly.Create(self);
fly.ShowModal;
end;


AND IT WORKS!!!

But I have a problem, when I click around the form, it disappears! I know it's in memory!!!

How can I solve this problem?
 
In your first problem, check the value of Bird, using the debugger, before you reference Bird.Edit1.Text. Chances are it's nil.

Whenever you declare an object variable in Delphi, it gets initialised to nil (i.e. 0). When you reference off a nil pointer, you get an error.

It looks like the way you were doing things, you were creating the Fly form from within the Bird form. This means that Bird has a variable called Fly, which contains a reference to a legitimate TFly object. But Fly does not necessarily get a reference to the real Bird.

Try putting both forms on the app's auto-create list (Project | Options | Forms). This might make things a bit smoother for you. Then you won't have to explicitly do an Application.CreateForm(Tfly, fly), because Delphi will do it for you, in your project file (Project | View Source).

Then again, I'm not sure if you can auto-create MDI forms.

The other approach would be to unload stuff from Fly in Bird, after the ShowModal:
Code:
    Ffly:=TFly.Create(self);
    Fly.ShowModal;
    Edit1.Text := Fly.fly_global_var_name_here;
-- Doug Burbidge mailto:dougburbidge@yahoo.com
 
The following works very fine:)

Ffly:=TFly.Create(self);
Fly.ShowModal;
Edit1.Text := Fly.fly_global_var_name_here;

- ANOTHER THING -

If I put in OnPaint or OnActivate this:

Edit1.Text := Fly.fly_global_var_name_here;

won't work! It won't refresh the MDIFORM "bird" when I close the "fly"... Could you tell me why?

 
Hmm. I would have thought that when the Fly form closed, the Bird form would indeed get an Activate event.

The first thing to do is to see if this is happening -- set a break point in BirdActivate(), and see if when you close Fly, you hit that break point.

If you are hitting the break point, then use Run | Add Watch to look inside some of Fly's global vars, and to look at the Fly variable itself, to see if it's nil or something. If you're creating Fly, doing a ShowModal, then Release'ing Fly, then your BirdActivate won't be able to get to Fly's variables because Fly will already have been Released. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top