Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 9th, 2005, 04:50 AM
lloydie-t lloydie-t is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2002
Location: UK
Posts: 523 lloydie-t User rank is Private First Class (20 - 50 Reputation Level)lloydie-t User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 17 h 3 m 13 sec
Reputation Power: 7
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;

Reply With Quote
  #2  
Old September 9th, 2005, 06:29 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,713 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 11 h 21 m 11 sec
Reputation Power: 1179
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

Reply With Quote
  #3  
Old September 9th, 2005, 07:27 PM
lloydie-t lloydie-t is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2002
Location: UK
Posts: 523 lloydie-t User rank is Private First Class (20 - 50 Reputation Level)lloydie-t User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 17 h 3 m 13 sec
Reputation Power: 7
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;

Reply With Quote
  #4  
Old September 9th, 2005, 07:32 PM
lloydie-t lloydie-t is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2002
Location: UK
Posts: 523 lloydie-t User rank is Private First Class (20 - 50 Reputation Level)lloydie-t User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 17 h 3 m 13 sec
Reputation Power: 7
hi,
f.SetParentForm(self); seemed to work

Thanks for your help

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Passing values between forms


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT