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

Hello, I have compilation error 1

Status
Not open for further replies.

davidchardonnet

Programmer
Mar 21, 2001
167
FR
Hello,

I have compilation error: Constant Expression expected

on the following code:

site.set_country(Edit1.Text);

Does somedy knows why i have this error?
the 'site' variable is an object of the following Class;

//-------------------------------------------------
type
CSite = class(CObjet)
procedure set_country(p_country:string);
private
m_country:string;
end;
//-------------------------------------------------
procedure CSite.set_country(p_country:string);
begin
m_country:=trim(p_country);
end;
//-------------------------------------------------

Thank you

David
 
CObjet is the parent class I defined:
Here is its definition:

type
CObjet = class
protected
request:TADOQuery;
public
...
end;

It looks OK but it does not work, Clive! I spend a lot of time on something I can't imagine it's a problem!! :)
 
Is the class declared in the same unit as the form?
Just a guess, but maybe you need to place the form name before the Edit box reference e.g.
Code:
site.set_country(Form1.Edit1.Text);
Meanwhile, I'll test the code myself! Clive [infinity]
 
Hey Clive,

Sorry I missed an important thing:

site is not a CSite object but a CSiteWork which is:

type CSiteWork = class(CSite)
private
public
end;

So 'site' uses the method set_country from its ancestor CSite.
 
I've got the following code and it compiles and runs fine. It's declared in the same unit as the form on which the Edit1 editbox is placed.
Code:
unit uSimpleExample;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ADODB;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  CObjet = class
  protected
    request: TADOQuery;
  end;

  CSite = class(CObjet)
    procedure set_country(p_country: string);
  private
    m_country: string;
  end;

  type CSiteWork = class(CSite)
  private
  public
  end;


var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  site: CSiteWork;
begin
  site := CSiteWork.Create;
  site.set_country(Edit1.Text);
  MessageDlg(site.m_country, mtInformation, [mbOK], 0);
  site.Free;
end;

{ CSite }

procedure CSite.set_country(p_country: string);
begin
  m_country := trim(p_country);
end;

end.
Clive [infinity]
 
My fault...

Sorry it was coming from a 'case' statement.... What a shame... You helped me discover it.... Again, you deserve a star for the time you spent for me...

Thanks again clive.

 
In my experince 'constant expected' error is almost always due to faulty case structures. A bit late to add this but it may be a good general tip.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top