Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use elements of a component as var

Status
Not open for further replies.

HobbyProgrammer

Programmer
Oct 31, 2003
7
TR
Hello

Would like to pass e.g. Edit.Text or ComboBox.Text or ComboBox.Items as a var into e.g.
Procedure DefineMyComponents(var Edit.Text : String;
var Box.Text : Sting;
var Box.Items : Tstrings);
by calling it e.g. with
DefineMyComponents(MyForm.Edit1.Text,
MyForm.ComboBox1.Text,
MyForm.ComboBox1.Items);

The Compiler (D5S) does not accept this. But how should it be done?

If I pass the complete component as a var parameter it works, like
Procedure DefineMyComponents(var Edit : TEdit;
var Box : TcomboBox);
But how should it be done if one only would like to pass parts of the component (and not the complete component)?

 
Hello

Edit1.Text is essentially just a string property of the Tedit class. So when passing Edit1.Text through to a procedure, rather define the procedure var as DefineMyComponents(Var Edit1Text,ComboBoxText : String).

In this way you can call the procedure by DefineMyComponents(MyForm.Edit1.Text,MyForm.ComboBox1.Text), but the actual declaration must define the type of variable being used. I'm also sure delphi doesn't like have periods(.) in variable names, which is why your code above doesn't work.

Hope it helps

Ant
 
Sorry, I made a mistake in my original thread...

What I actually did test and what didn't work was without periods, like e.g.

Procedure DefineMyComponents(var EditText : String;
var BoxText : Sting;
var BoxItems : TStrings);

What do I have to change to get it working?
 
Procedure DefineMyComponents(var EditText : String;
var BoxText : Sting; <<<<<
var BoxItems : TStrings);

I asume this is actual code, if so, your problem lies there.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
[/b]
Great Delphi Websites faq102-5352
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top