Jump to content

Syntax error?


Recommended Posts

try something like this

 

 
  TForm1=class(TW3form) 
  private 
    {$I 'Form1:intf'} 
    fCaption: String; 
    function GetCaption: String; 
    procedure SetCaption(Value: String); 
  protected 
    procedure InitializeObject; override; 
    procedure FinalizeObject; override; 
    procedure StyleTagObject; reintroduce; virtual; 
    procedure Resize; override; 
  public 
   property FrmCaption: String read GetCaption write SetCaption; 
  end; 

implementation 

{ TForm1 } 

function TForm1.GetCaption: String; 
begin 
 result:= fCaption; 
end; 

procedure TForm1.SetCaption(Value: String); 
begin 
 if fCaption <> Value then 
 fCaption:= Value; 
end; 

 

Shane

Link to post
Share on other sites

oh, sorry, I think you need just this

 

 
  TForm1=class(TW3form) 
  private 
    { Private methods } 
    {$I 'Form1:intf'} 
    fCaption: String; 
  protected 
    { Protected methods } 
    procedure InitializeObject; override; 
    procedure FinalizeObject; override; 
    procedure StyleTagObject; reintroduce; virtual; 
    procedure Resize; override; 
  public 
   property FrmCaption: String read fCaption write fCaption; 
  end; 

Link to post
Share on other sites

Hi Shane,

Indeed using a getter and a setter does not result in a Syntax Error. But using the Caption (string) property of a TW3Label does. So, I was wondering whether this is an 'undocumented feature' (read bug :-).

 

Using a private member, fCaption, is also not a solution since the purpose is to

display a caption on a form.

 

Thanks for the feedback.

Link to post
Share on other sites

Sorry, I wasn't quite sure what you were trying to do. Try this

 

 
unit Form1; 

interface 

uses 
  w3system, w3graphics, w3components, w3forms, w3fonts, w3borders, w3application, 
  w3label; 

type 
  TForm1 = class(TW3form) 
  private 
    {$I 'Form1:intf'} 
    lbl: TW3Label; 
    function GetCaption: String; 
    procedure SetCaption(Value: String); 
  protected 
    procedure InitializeObject; override; 
    procedure FinalizeObject; override; 
    procedure StyleTagObject; reintroduce; virtual; 
    procedure Resize; override; 
  public 
    property FrmCaption: String read GetCaption write SetCaption; 
  end; 

implementation 

{ TForm1 } 

function TForm1.GetCaption: String; 
begin 
 result := lbl.Caption; 
end; 

procedure TForm1.SetCaption(Value: String); 
begin 
 if lbl.Caption <> Value then 
   lbl.Caption:= Value; 
end; 

procedure TForm1.InitializeObject; 
begin 
  inherited; 
  {$I 'Form1:impl'} 
  lbl:= TW3Label.Create(self); 
  lbl.top:= 10; 
  lbl.Left:= 10; 
  lbl.Width:= 100; 
  //change caption here 
  self.FrmCaption:= 'SHANE'; 
end; 

Link to post
Share on other sites

> I have a TW3Label on a Form and the following declaration

> property FrmCaption:string read W3Label1.Caption write W3Label1.Caption;

 

The syntax for expressions requires parenthesis, ie.

 

property FrmCaption:string read (W3Label1.Caption) write (W3Label1.Caption);

 

For more details, see http://delphitools.info/2013/02/14/property-expressions-and-statements/

 

I'm not sure in which version of Smart this was made available though...

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...