Search code examples
androiddelphiconstructorbluetoothdelphi-xe6

How I can use the Constructor in Delphi for transfer Objects with two Forms?


hi I have a Delphi constructor Problem. I want a Constuctor with a Parameter of my own class. I have two Forms.. in the first form my class object get informations and than i call the second form. by the second form I call the constructor and give him my class object.

here the code: TForm2

...
constructor TForm2.create(bluetoothconfiguration : TAndroidBluetooth);
  begin
    inherited create;

    bt := bluetoothconfiguration; 

  end;
...

here I call the constructor: TForm1

...
procedure TForm1.lv_devicesItemClick(const Sender: TObject;
  const AItem: TListViewItem);
   var
   form : TForm2;
begin
      bt.CreateConnectionToBluetoothDevice(AItem); //Stellt eine Verbindung mit einem Gerät her

      form := TForm2.Create(bt); //bt is the class object with the information

      form.Show();

end;
...

I want to send the second form my Object :(


Solution

  • The inherited constructor that you are calling expects to be passed an owner parameter. You are not doing that.

    You should add an owner parameter to the constructor, and pass it to the inherited constructor:

    constructor TForm2.Create(AOwner: TComponent; Config: TAndroidBluetooth);
    begin
      inherited Create(AOwner);
      ....
    end;
    

    Then pass an owner when you create the form:

    form := TForm2.Create(Self, bt);
    

    Perhaps you might wish to use a different owner, I cannot tell from here.

    One final word of advice. When asking a question about a compilation error, always include the compilation error text in the question so that we know what you are asking about.