The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Delphi Programming
|
Problems with components on different forms
Discuss Problems with components on different forms in the Delphi Programming forum on Dev Shed. Problems with components on different forms Delphi Programming forum discussing Delphi related topics including Kylix, C++ Builder, and more. Delphi is a high-performance language, originally based on the PASCAL language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 30th, 2003, 06:26 PM
|
|
Contributing User
|
|
Join Date: May 2002
Location: UK
Posts: 563

Time spent in forums: 1 Day 23 h 54 m 22 sec
Reputation Power: 12
|
|
|
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
Code:
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
Code:
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
Last edited by lloydie-t : November 30th, 2003 at 06:29 PM.
|

December 1st, 2003, 03:33 AM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
Code:
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.
|

December 1st, 2003, 05:03 PM
|
|
Contributing User
|
|
Join Date: May 2002
Location: UK
Posts: 563

Time spent in forums: 1 Day 23 h 54 m 22 sec
Reputation Power: 12
|
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|