Recent

Author Topic: Error: Invalid value for property  (Read 9322 times)

ThomasK1201

  • New Member
  • *
  • Posts: 31
Error: Invalid value for property
« on: March 09, 2015, 09:26:26 pm »
Hi guys

I have a project with 4 forms. I just added the 4th and now I get an error when I try to run the project. Out for nowhere. I get this error: Project [Name] raised exception class 'EReadError' with message: Invalid value for property.
What is the problem and how can I solve it?
These are the codes of my forms:

Form 1:
(This is my mainform and from here all the other forms can be opened)
Code: [Select]
unit MainForm;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
  PlusMakkelijkUnit, MinMakkelijkUnit, RekenmachineUnit;

type

  { TFormMenu }

  TFormMenu = class(TForm)
    HoofdMenu: TMainMenu;
    LeerlingenMenu: TMenuItem;
    MinMakkelijkShow: TMenuItem;
    PlusMenu: TMenuItem;
    PlusMakkelijkShow: TMenuItem;
    MinMenu: TMenuItem;
    VermenigvuldigenMenu: TMenuItem;
    DelenMenu: TMenuItem;
    MachtsheffenMenu: TMenuItem;
    InhoudsmatenMenu: TMenuItem;
    OppervlakteMenu: TMenuItem;
    AllesDoorElkaarMenu: TMenuItem;
    HandleidingMenu: TMenuItem;
    Docenten: TMenuItem;
    HandleidingMenuDocenten: TMenuItem;
    procedure MinMakkelijkShowClick(Sender: TObject);
    procedure PlusMakkelijkShowClick(Sender: TObject);
    procedure RekenmachineClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  FormMenu: TFormMenu;

implementation

{$R *.lfm}

{ TFormMenu }

procedure TFormMenu.PlusMakkelijkShowClick(Sender: TObject);
begin
   FormPlusMakkelijk.Show;
end;

procedure TFormMenu.MinMakkelijkShowClick(Sender: TObject);
begin
   FormMinMakkelijk.Show;
end;

procedure TFormMenu.RekenmachineClick(Sender: TObject);
begin
  FormRekenmachine.Show;
end;

end.

Form 2:
(Form 2 actually has nothing to do with form 3, but I give it to you just for sure)
Code: [Select]
unit PlusMakkelijkUnit;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TFormPlusMakkelijk }

  TFormPlusMakkelijk = class(TForm)
    Edit10: TEdit;
    Edit11: TEdit;
    Antwoord5: TEdit;
    Edit13: TEdit;
    Edit14: TEdit;
    Antwoord6: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Antwoord2: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Antwoord3: TEdit;
    Antwoord4: TEdit;
    PlusMakkelijkNakijken: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Antwoord1: TEdit;
    //procedure Edit3Change(Sender: TObject);
    procedure PlusMakkelijkNakijkenClick(Sender: TObject);
    //procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  FormPlusMakkelijk: TFormPlusMakkelijk;

implementation

{$R *.lfm}

{ TFormPlusMakkelijk }

procedure TFormPlusMakkelijk.PlusMakkelijkNakijkenClick(Sender: TObject);
begin
   Antwoord1.Enabled := False;
   Antwoord2.Enabled := False;
   Antwoord3.Enabled := False;

  If Antwoord1.Text = '47'
  then Antwoord1.Color := clGreen;
  If Antwoord1.Text <> '47'
  then Antwoord1.Color := clRed;

  If Antwoord2.Text = '81'
  then Antwoord2.Color := clGreen;
  If Antwoord2.Text <> '81'
  then Antwoord2.Color := clRed;

  If Antwoord3.Text = '153'
  then Antwoord3.Color := clGreen;
  If Antwoord3.Text <> '153'
  then Antwoord3.Color := clRed;

  If Antwoord4.Text = '102'
  then Antwoord4.Color := clGreen;
  If Antwoord4.Text <> '102'
  then Antwoord4.Color := clRed;

  If Antwoord5.Text = '45'
  then Antwoord5.Color := clGreen;
  If Antwoord5.Text <> '45'
  then Antwoord5.Color := clRed;

  If Antwoord6.Text = '102'
  then Antwoord6.Color := clGreen;
  If Antwoord6.Text <> '102'
  then Antwoord6.Color := clRed;
end;


end.

Form 3:
(This is the form I added as last one)
Code: [Select]
unit MinMakkelijkUnit;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;

type
  TFormMinMakkelijk = class(TForm)
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  FormMinMakkelijk: TFormMinMakkelijk;

implementation

{$R *.lfm}

end.

Form 4:
(This is the calculator of my project and has, just like form 2, nothing to do with form 3)
Code: [Select]
unit RekenmachineUnit;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TFormRekenmachine }

  TFormRekenmachine = class(TForm)
    Antwoord: TEdit;
    KnopMacht: TButton;
    KnopWortel: TButton;
    KnopOptellen: TButton;
    RekenmachineVenster2: TEdit;
    KnopDelen: TButton;
    KnopVermenigvuldigen: TButton;
    KnopAftrekken: TButton;
    C: TButton;
    RekenmachineVenster1: TEdit;
    procedure CClick(Sender: TObject);
    procedure KnopAftrekkenClick(Sender: TObject);
    procedure KnopDelenClick(Sender: TObject);
    procedure KnopMachtClick(Sender: TObject);
    procedure KnopOptellenClick(Sender: TObject);
    procedure KnopVermenigvuldigenClick(Sender: TObject);
    procedure KnopWortelClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  FormRekenmachine: TFormRekenmachine;
  x1, x2, x3 : string;
  d1, d2, d3 : double;


implementation

{$R *.lfm}

{ TFormRekenmachine }



procedure TFormRekenmachine.KnopOptellenClick(Sender: TObject);
begin
   Antwoord.Caption := FloatToStr(StrToFloat(RekenmachineVenster1.Text) + StrtoFloat(RekenmachineVenster2.Text));
end;

procedure TFormRekenmachine.KnopVermenigvuldigenClick(Sender: TObject);
begin
  Antwoord.Caption := FloatToStr(StrToFloat(RekenmachineVenster1.Text) * StrtoFloat(RekenmachineVenster2.Text));
end;

procedure TFormRekenmachine.KnopWortelClick(Sender: TObject);
begin
  Antwoord.Caption := FloatToStr(Sqrt(StrToFloat(RekenmachineVenster1.Text)));
end;

procedure TFormRekenmachine.KnopAftrekkenClick(Sender: TObject);
begin
   Antwoord.Caption := FloatToStr(StrToFloat(RekenmachineVenster1.Text) - StrtoFloat(RekenmachineVenster2.Text));
end;

procedure TFormRekenmachine.CClick(Sender: TObject);
begin
  RekenmachineVenster1.Caption := '';
  RekenmachineVenster2.Caption := '';
  Antwoord.Caption := '';
end;

procedure TFormRekenmachine.KnopDelenClick(Sender: TObject);
begin
  Antwoord.Caption := FloatToStr(StrToFloat(RekenmachineVenster1.Text) / StrtoFloat(RekenmachineVenster2.Text));
end;

procedure TFormRekenmachine.KnopMachtClick(Sender: TObject);
begin
  Antwoord.Caption := FloatToStr(StrToFloat(RekenmachineVenster1.Text) * StrToFloat(RekenmachineVenster1.Text));
end;

end.

Nitorami

  • Sr. Member
  • ****
  • Posts: 496
Re: Error: Invalid value for property
« Reply #1 on: March 09, 2015, 09:54:31 pm »
The source alone does not help, it cannot be compiled without the project files (e.g. *.lfm).

Check to which events your KnopClick procedures are linked. It might be that the text in RekenmachineVenster2.Text is not a numeric value, and if the event that calls it is something else than OnClick then KnopClick might already be called at program start and cause the error. And you should pre-set RekenmachineVenster2.Text with valid numeric valuse e.g. '0'.

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Error: Invalid value for property
« Reply #2 on: March 09, 2015, 10:37:53 pm »
This is -most probably- the same error as for your former project: http://forum.lazarus.freepascal.org/index.php/topic,27562.msg170670.html#msg170670

This means that you've begun to create a new event, for one of your forms or one of their controls, and finally not implemented it. In fact, you've even removed it, I should say.

For instance, by double-clicking on a new form, the Lazarus IDE will create all the necessary code and object for an OnCreate event.

Sample (for a new project):
- "procedure TForm1.FormCreate(Sender: TObject);" in unit1.pas,
- associated to "OnCreate = FormCreate" for object Form1: TForm1 in unit1.lfm

But if you remove manually "procedure TForm1.FormCreate(Sender: TObject);" in unit1.pas, the OnCreate event is still present in unit1.lfm. It must also be removed, or else you'll get the kind of error you're experimenting.

Theoretically, when saving or building the whole project, the unused OnCreate event (or any other unused event) in the .lfm file should be proposed to be removed. See attached Capture.png image.

In your particular case, it seems that there is an issue which prevents this message to be displayed. May be because you've not asked to remove it, the first time this message has been displayed.

You could manually remove it from the concerned .lfm file, but it's NOT recommended unless you do know EXACTLY what your are doing.

So, load your project in the Lazarus IDE and then:
- display all your forms one after one: (IDE menu) Window-> mainform, and so on ...
- add a control (for instance a pusbutton) in each of your forms and delete it immediately (click on it and the press the "Del" key),
- (re)save, then (re)build your whole project,
- when re-saving the concerned form/unit, you should now get the same message as the one displayed in my attached Capture.png image,
- this time, DO CLICK on the "Remove them" choice.

The next time you'll get this message in the future, always choose the "Remove them" button.  Doing so, you'll avoid this kind of error.


** EDIT ** : if you don't get the concerned message during the above (re)save step, it means that your incorrect .lfm file has not
been updated correctly. Which also implies that your error won't be fixed.

** EDIT2 **: modifications in the above steps to force the "re-saving" of the offended form.
« Last Edit: March 14, 2015, 09:40:42 pm by ChrisF »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Error: Invalid value for property
« Reply #3 on: March 10, 2015, 07:56:36 am »
Pressing Ctrl+F9 should compile the project and tell about that kind of event link errors.

Also i just tested and i get exactly that error if i leave old event in place in Object Inspector.
« Last Edit: March 10, 2015, 07:58:27 am by User137 »

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Error: Invalid value for property
« Reply #4 on: March 10, 2015, 01:34:06 pm »
Pressing Ctrl+F9 should compile the project and tell about that kind of event link errors.

It doesn't necessarily (you can make a try to verify it).

Building the project just causes it to be saved first if some modifications are pending. But if there are no modifications in the concerned form, there is no "re-saving" for this form, and the message is not displayed.

As far as I have tested, the check (i.e. missing event in code) is done only when the form is saved.
« Last Edit: March 10, 2015, 01:43:15 pm by ChrisF »

 

TinyPortal © 2005-2018