I am a student and Delphi is not really my primary environment for programming. I know how it works and I'm completely familiar with its layout. I recently received a task in which I have to use arrays in order to list them in a listbox via integer and string. The idea is very simple and the program itself is very easy to make.
The problem comes when I try to declare a constant under the private or public it just shows and error message stating "'END' expected but 'CONST' found". I have worked with public and private variables and constants for a while now but I'm not really sure what's going on.
The code is as follows:
type
TForm1 = class(TForm)
edtDateTime: TEdit;
lstListArrayValues: TListBox;
gbpIntegerArrayOptions: TGroupBox;
gbpStringArrayOptions: TGroupBox;
gbpListBoxOptions: TGroupBox;
btnInitializeIntArray: TButton;
btnAssignIntArray: TButton;
btnDoubleIntArray: TButton;
btnInitializeStrArray: TButton;
btnAssignStrArray: TButton;
btnCapitalStrArray: TButton;
btnDisplayArray: TButton;
btnClearListbox: TButton;
btnDeleteSelected: TButton;
XPManifest1: TXPManifest;
procedure FormCreate(Sender: TObject);
procedure btnInitializeIntArrayClick(Sender: TObject);
private
{Private Declarations}
Const
nItems = 5;
var
nBasicsIntArray : array [0..(nItems - 1)] of integer;
nBasicsStrArray : array [0..(nItems - 1)] of string;
public
{ Public declarations }
end;
When I run the application it says "'END' expected but 'CONST' found". I am using Windows 7 and Delphi 7 and I have not had this problem before.
It could honestly be that I'm missing something stupid but I've overlooked everything and I can't seem to find the cause of the problem.
The ability to declare constants inside a class was not supported in Delphi 7. That language feature was added in a later release.
Declare your constant outside the class.
The same is true of your use of var. That syntax is not supported in Delphi 7. You should simply remove the var keyword from your class declaration.
As written above, a solution can be to move your local constant to global position under Delphi 7. Here is a code sample:
Const
nItems = 5;
type
TForm1 = class(TForm)
edtDateTime: TEdit;
//...
private
nBasicsIntArray : array [0..(nItems - 1)] of integer;
nBasicsStrArray : array [0..(nItems - 1)] of string;
//...
end;
Also you can use "const" and "type" keywords multiple times to keep things together.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With