357mag 2 Posted December 12 I've got a program that asks the user to enter the name of a boy, and the name of a girl. Then he clicks on the Add Couple button, and the boy and girl are added to a listbox together. They're going to a dance together. But the compiler will not let me list the variables on individual lines. It will only list my variables on one line. Even my book says you can also write it like this. This does not work: procedure TFormStringConcatenation.ButtonAddCoupleClick(Sender: TObject); begin Var Boy: string; Girl: string; Couple: string; Boy := EditEnterBoy.Text; Girl := EditEnterGirl.Text; Couple := Boy + ' and ' + Girl; ListBoxCouple.Items.Add(Couple); This however does work: procedure TFormStringConcatenation.ButtonAddCoupleClick(Sender: TObject); begin Var Boy, Girl, Couple: string; Boy := EditEnterBoy.Text; Girl := EditEnterGirl.Text; Couple := Boy + ' and ' + Girl; ListBoxCouple.Items.Add(Couple); end; Share this post Link to post
Uwe Raabe 2064 Posted December 12 You are using inline variables. Try moving the variables declaration before the begin. procedure TFormStringConcatenation.ButtonAddCoupleClick(Sender: TObject); Var Boy: string; Girl: string; Couple: string; begin Boy := EditEnterBoy.Text; Girl := EditEnterGirl.Text; Couple := Boy + ' and ' + Girl; ListBoxCouple.Items.Add(Couple); 1 Share this post Link to post
357mag 2 Posted December 12 That won't work either. Compiler says "undeclared identifier." Share this post Link to post
Anders Melander 1815 Posted December 12 Just now, 357mag said: That won't work either. Yes it does. Try again and this time do it exactly like Uwe showed you. 1 Share this post Link to post
Lars Fosdal 1793 Posted December 13 Why won't this work with inline vars? Is it the ListBox.Items.Add that doesn't copy the Couple string? Share this post Link to post
Uwe Raabe 2064 Posted December 13 With inline vars this works: Var Boy, Girl, Couple: string; But this does not: Var Boy: string; Girl: string; Couple: string; Share this post Link to post
Sherlock 663 Posted December 13 What does "work" mean in this case? No Compiler error? Share this post Link to post
Lajos Juhász 295 Posted December 13 procedure TForm1.FormCreate(Sender: TObject); begin Var Boy: string; Girl: string; Couple: string; end; For those who doesn't have a modern compiler. Of course inline var is not a block thus it will produce errors: [dcc32 Error] Unit1.pas(29): E2003 Undeclared identifier: 'Girl' [dcc32 Error] Unit1.pas(29): E2029 '(' expected but ';' found [dcc32 Error] Unit1.pas(30): E2003 Undeclared identifier: 'Couple' [dcc32 Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas' Failed 1 Share this post Link to post