0
votes

I am toying around in Delphi XE6, and add this procedure on a button:

procedure TTabbedForm.btnLoadingClick(Sender: TObject);
var
  dlg: Unit2;

begin

  dlg := Form2.Create(nil);
  Form2.ShowModal();

end;

Delphi gives me the following error while compiling:

[DCC Error] TabbedTemplate.pas(53): E2029 '.' expected but ';' found
[DCC Error] TabbedTemplate.pas(55): E2029 ';' expected but 'BEGIN' found
[DCC Fatal Error] Speelpleintjes.dpr(7): F2063 Could not compile used unit 'TabbedTemplate.pas'

Line 53 being: dlg: Unit2;

Honestly i'm quite puzzled, the syntax seems correct, the procedure is auto generated from the events tab.

Any suggestions?

1
Is Unit2 a class or a unit? Is Form2 a class or an object? There seems to be a lot of confusion in those few lines of code. If dlg is an object of class Form2, then maybe you want to do dlg.ShowModal()... not Form2.ShowModal().Frazz
You should work on some basic tutorials ... this piece of source is wrong at all (except the autogenerated parts)Sir Rufo
I removed everything and re-added the form with normal names. Now the error is gone, but i'm having some other issues.. Thanks for the help, i need to RTFM some more i think ;) @SirRufo It was copied from an embarcadero wiki item, but i think i missed a few steps.Michel Bijlsma

1 Answers

3
votes

If Unit2 is another unit in your project (judging by it's name it probably is), it can't be used as a type directly. Units only declare things. That's why the compiler is expecting a . since you can prefix an identifier with the unit's name to direct to a declaration in that specific unit.

To correct this, write dlg: TForm2;

Also it's common practice to call constructors from the class declaration, not a variable so change it to:

dlg := TForm2.Create(nil);

Or use the Form2 variable, which typically will hold an instance of TForm2 already. By default extra forms added to a Delphi project are created hidden, ready for Show or ShowModal.