Like Rory Daulton already stated, Caption is NOT is string;
it's a property of type string: you can read is as a string
and you can write is as a string, but it isn't a string.
Let me try to explain it using the following extraction of
property "getters" and "setters":
Type
TFooControl = Class(TComponent)
fCaption : String;
// Blahblahblah...
Protected
Function GetCaption : String;
Procedure SetCaption(ACaption : String);
Published
Property Caption : String Read GetString Write SetString;
End;
As you can see, the property Caption is not a string, its only
a "handle" to a function (GetString) to get the string and a
procedure (SetString) to set the string, but in itself it isn't
a string at all.
If you want a quick and good solution, you can pass the complete
control in question (which is actually a "pointer" and thus can
be passed by reference) to the function:
Procedure KeyBoard(Const AButton : TButton);
Begin
If Assigned(AButton) Then
AButton.Caption := 'SomeText';
End;
Greetz,
Peter.
> -----Original Message-----
> From: [email protected]
> [mailto:[EMAIL PROTECTED] On Behalf Of safeldt2
> Sent: Friday, September 09, 2005 12:31 PM
> To: [email protected]
> Subject: [delphi-en] Re: Passing a caption as var string.
>
>
> --- In [email protected], Vahan Yoghoudjian
> <[EMAIL PROTECTED]> wrote:
> > Button.Caption is of Type TCaption, either declare your
> parameter is TCaption...
>
> I tried that but then I get this error:
>
> "Constant object cannot be passed as var parameter"
>
> Why is it a constant when I can give it a new value at runtime?
> btCompound.Caption := 'a text';
>
>
> The main problem is that i need to call the procedure many times in my
> project and found it more ellegant not to use temporary variables.
>
> Uffe
------------------------ Yahoo! Groups Sponsor --------------------~-->
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/i7folB/TM
--------------------------------------------------------------------~->
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/