|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Passing values between forms
On from an earlier post. I am trying to pass some values from a dialog form to another dialog form. but I do not seem to be able to achieve it.
here is the following code.Where am I going wrong? Code:
//so we open the form here
procedure TAddRes.NewButtonClick(Sender: TObject);
var
f:TAddLod;
begin
f := TAddLod.Create(Self);
try
f.ShowModal;
finally
f.Release;
end;
end;
//when the form is completed we add to database and try to copy editbox.text to another editbox on mainform.
procedure TAddLod.OKbuttonClick(Sender: TObject);
begin
if (TitleEdit.Text = '') or (FirstNEdit.Text = '') or (LastNEdit.Text ='') or (PostEdit.Text = '') or (AddrMemo.Text = '')
then begin
ShowMessage('Please Complete All Required Fields');
end
else
begin
//copy to mainform editbox
Addres.TitleEdit.Text := FirstNEdit.Text+', '+LastNEdit.Text+' - '+PostEdit.Text;
//add to database
MysqlQuery1.SQL.Clear;
MysqlQuery1.SQL.Add('Insert into lodgers ');
MysqlQuery1.SQL.Add('(title, firstname, lastname, company, postcode, phone, mobile, address) ');
MysqlQuery1.SQL.Add('values ');
MysqlQuery1.SQL.Add('('''+titleEdit.Text+''','''+FirstNEdit.Text+''','''+LastNEdit.Text+''','''+comp Edit.Text+'''');
MysqlQuery1.SQL.Add(','''+postEdit.Text+''','''+PhoneEdit.Text+''','''+MobileEdit.Text+''','''+AddrM emo.Text+''')');
MysqlQuery1.Open;
//close window
ModalResult := mrOk;
end;
end;
|
|
#2
|
||||
|
||||
|
You need to pass the dialog box the address of the parent form, so it can update it. You can do this by making a public method in TAddLod, which you can use to pass the address of your parent form ahead of time.
Code:
//so we open the form here
procedure TAddRes.NewButtonClick(Sender: TObject);
var
f:TAddLod;
begin
f := TAddLod.Create(Self);
try
f.SetParentForm(this);
f.ShowModal;
finally
f.Release;
end;
end;
Then for the code for TAddLod. Code:
uses
..., Addres;
...
private:
parentForm: TAddres;
public:
procedure SetParentForm(aForm : TAddres);
...
end;
procedure TAddLod.SetParentForm(aForm: TAddres);
begin
parentForm = aForm;
end;
procedure TAddLod.OKbuttonClick(Sender: TObject);
begin
if (TitleEdit.Text = '') or (FirstNEdit.Text = '') or (LastNEdit.Text ='') or (PostEdit.Text = '') or (AddrMemo.Text = '')
then begin
ShowMessage('Please Complete All Required Fields');
end
else
begin
//copy to mainform editbox
parentForm.TitleEdit.Text := '.....'
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
|
#3
|
|||
|
|||
|
OK, I am getting an error '[Error] ResAdd.pas(270): E2003 Undeclared identifier: 'this''. Any Ideas?
Code:
procedure TAddRes.NewButtonClick(Sender: TObject);
var
f:TAddLod;
begin
f := TAddLod.Create(Self);
try
f.SetParentForm(this); //something going wrong here
f.ShowModal;
finally
f.Release;
end;
end;
|
|
#4
|
|||
|
|||
|
hi,
f.SetParentForm(self); seemed to work Thanks for your help |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Passing values between forms |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|