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

Setting lbl caption from procedure

Status
Not open for further replies.

xeonite

Programmer
Jan 3, 2003
3
CA
Hello,
I'm using Delphi 6.0 Personal for my programming project at school. The goal is to create a small RPG.

The problem is today I tried to set a label caption from a procedure which looks like this...

procedure name(value1,value2,value3:integer);
begin
label.caption:='text';
end;

Now that gave me an error stating that label was an unknown identifier. I know what the problem is, but do not know a solution to it. How do I change the properties of that label from that style of a procedure. Also that procedure is called from a button click event and after doing several tasks, including changing several labels, calls another procedure.

Thanks in advance.
 
Just to add (is there an edit button I coudln't find it) I've figured out how to do what I needed. But a smaller question remains if I'm assigning an integer or a char variable to a caption of a label. Is there an easier way of doing it then converting to a string variable first?
 
(1) This would work if "label" is the name of the TLabel:
Code:
procedure name(value1,value2,value3:integer);
begin
  label.caption:='text';
end;
(2) To use an integer in a caption it must be converted to a string, so no there is no easier way:
Code:
   Label1.Caption := 'Item # ' + IntToStr(nItem);
This is part of Delphi's "strong typing."
 
Apparently that your procedure isn't a memeber of a form, thus you must use your label specifing a form that owns it i.e. Form1.label.caption := 'blah blah'.

--- markus
 
Whenever I need to add an integer to a string, I use:
MyString := format( 'Some Text %d', [IntegerValue] );

I find this is faster than calling IntToStr and works for a lot of data types including other strings. You just replace the %d with another token. Look in the Delphi help for format and there's a help link showing the tokens for other data types.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top