Board index » delphi » Setting component properties on a different form

Setting component properties on a different form

Hi Everyone!

I have managed to stump my local Delphi gurus so I'd really appreciate any input from anyone else.

I'm updating a MDI application.  After I finish processing the currently active form, form2, I want to set a component property of
a component that is on form1.  The component is a TRadioGroup and I'm trying to set the ItemIndex property. I try to set it from
form2 using:

form1.componentName.ItemIndex := value;

This compiles fine but I get a dreaded GPF when this line is executed.  The other weird thing is that when I step through in
debug and evaluate form1.componentName.ItemIndex, it evaluates to 228.  The valid values are 0, 1, or 2.
I tried creating a published property in form1 to indirectly set this component using:

property indx: integer read GetComponentIndex write SetComponentIndex;  

procedure form1.SetComponentIndex (value:integer);
   componentName.ItemIndex := value;

In form2 I have      form1.indx := value;

I still get a GPF in form1.SetComponentIndex.  Any thoughts anyone???

Thanks for your help,
Maria Malone


Re:Setting component properties on a different form

On 2 Aug 1996 15:14:15 GMT, you smacked the keyboard
repeatedly to write:

>Hi Everyone!

>I have managed to stump my local Delphi gurus so I'd really appreciate any input from anyone else.

Thats a very odd problem.  I created a simple test app that has the
parent form (set to fsMDIForm) and a child form (fsMDIChild) and on
the parent form (Form1) I have a radio group.  On the child form
(Form2) I have 3 buttons, each buttons sets the radio group from a
value of 0 to 2.  This all works perfectly as expected.

What it sounds like to me is that your code is getting executed when
it should not be.  What I mean by this is that if you try to access
Form2 from Form1's OnCreate event you would get a GPF (this is all
assuming you use AutoCreate) because Form2 has yet to be created.

First If you could supply a code snipet it might help.  If you cant
because its too large or difficult to isolate then try building a
simple app like the one above and see if that works.

Second, check where you are accessing the radio group (i.e. is it in
an event for the Form2 or in an OnClick event for a button) and see if
there is a chance for that code to get created before the radio group
is actually created.

Third, do a check prior to your setting to see if the RadioGroup is
accessable like:

        if Form1.RadioGroup <> nil then

Fourth, if you build a sample app and it works, and you are doing the
same thing in the real app, then rebuild the project (i.e. delete all
DCU files, the EXE file,) and then do a build all.

Brien King

Other Threads