Helpful Information
 
 
Category: Delphi Programming
Problems with components on different forms

I have just started writing my first application in delphi and I am now stuck communicating between forms. I am using a serial port component TnrComms which has a main serial port component and a Device dropdown box component. I wish to select the dropdown box on a different form in the same project, but I don't know how to reference the main serial port component so that I can select that component in the object inspector. Have a look and point me in the right direction.

form 1


unit datacollex;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls, ToolWin, ActnMan, ActnCtrls, StdCtrls, ComCtrls,
nrclasses, nrcomm, dataport;

type
TMainForm = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
A1: TMenuItem;
Options1: TMenuItem;
Options2: TMenuItem;
Disconnect1: TMenuItem;
Help1: TMenuItem;
SerialPortSettings1: TMenuItem;
Quit1: TMenuItem;
Panel2: TPanel;
ActionToolBar1: TActionToolBar;
IncomingDataEdit: TRichEdit;
Panel1: TPanel;
OutgoingSQLEdit: TRichEdit;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
nrComm1: TnrComm; // this is the component
SelectPort1: TMenuItem;
procedure SelectPort1Click(Sender: TObject);
procedure SerialPortSettings1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.SelectPort1Click(Sender: TObject);
var dlg: TPortForm;
begin
dlg := TPortForm.Create( Self);
dlg.ShowModal;
end;

procedure TMainForm.SerialPortSettings1Click(Sender: TObject);
begin
nrComm1.ConfigDialog;
end;

end.


Form 2


unit dataport;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, ComCtrls, nrcomm, nrcommbox;

type
TPortForm = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Quit1: TMenuItem;
PortOk: TButton;
PortCancel: TButton;
nrDeviceBox1: TnrDeviceBox; //this is the dropdown box
private
{ Private declarations }
public
{ Public declarations }
end;

var
PortForm: TPortForm;

implementation

{$R *.dfm}

end.

Thanx

procedure TMainForm.OnCreate(Sender: TObject);
begin
nrComms1.assocDropdown:=Form2.nrDeviceBox;
end;
"assocDropdown" is the property name, the same like in the object inspector.
This should do it although I can not test it and I don't know your Delphi version either.
You have to set the form create order so that form2 will be created before form1 and connect the procedure above to the OnCreate handler of Form1.

hth,
M.

Hi M,
I managed to sort it out I added datacollex to the uses of dataform and added dataform was put in the implementation uses to stop circular references and that seem to this problem out. I do need some more advise, but will start a new post.

Thanx










privacy (GDPR)