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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

better way to pass Tedit.text to a validation procedure

Status
Not open for further replies.

CADTenchy

Technical User
Dec 12, 2007
237
GB

Currently I'm passing the text from my Tedit's to a tempory string variable then calling a validation procedure passing the string as the text to validate, like so:
Code:
TempString := edit1.text;
ValidateProc(Tempstring);

and my validation procedure looks like this:
Code:
procedure ValidateProc(var TextToCheck: string);
begin
if TextToCheck = good then result=good;
end;

What I'd really like to do is pass the edit1.text to the validation procedure directly, without using a tempory holding string.
Is this possible?

Steve (Delphi 2007 & XP)
 
well,

if you don't change TextToCheck in the ValidateProc then you don't need the var parameter and you can call the procedure without the need of a temp holding variable.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 

I have tried (earthandfire), I can't pass the edit1.text as a string as it raises the error:
'E2033 Types of actual and formal var parameter must be identical'

I also tried to get my validation procedure to accept Tedit.Text's instead of strings, but that caused an error too.

Daddy, yes that would work, but I want to call the same routine to validate different Tedits..


Steve (Delphi 2007 & XP)
 
remove the var as per daddy.
procedure ValidateProc(TextToCheck: string);

then your procedure will accept any string.

ValidateProc(Edit1.Text);
ValidateProc(Edit2.Text);
ValidateProc('this string');

var test: string
ValidateProc(test);

and so on.


Aaron
 

Thanks Aaron and Daddy.

I'd mis-interpreted what Daddy said, I didn't realise I could take the var from the proc def.

Done that and it works, cheers!!


Steve (Delphi 2007 & XP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top