Dear All,

Could you tell me what is wrong or missing for my coding?

Cheers,

unit Example3;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Button1: TButton;
    Button2: TButton;
    Edit6: TEdit;
    Edit7: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  sum, average: integer;
begin
  sum:=StrToInt(Edit1.Text)+StrToInt(Edit2.Text)+StrToInt(Edit3.Text)+StrToInt(Edit4.Text)+StrToInt(Edit5.Text);
  average:=sum div 5;
  Edit6.Text:=IntToStr(sum);
  Edit7.Text:=IntToStr(average);
end;

end.

Dear All,

Could you tell me what is wrong or missing for my coding?

Cheers,

...

Is there a specific problem that you are running into? The code works just fine with Lazarus and Delphi both.

Is there a specific problem that you are running into? The code works just fine with Lazarus and Delphi both.

Sorry,

I forget to attach the document.

Cheers,

The method:

procedure TForm1.Button1Click(Sender: TObject);
var
  sum, average: integer;
begin
  sum:=StrToInt(Edit1.Text)+StrToInt(Edit2.Text)+StrToInt(Edit3.Text)
  +StrToInt(Edit4.Text)+StrToInt(Edit5.Text);
  average:=sum div 5;
  Edit6.Text:=IntToStr(sum);
  Edit7.Text:=IntToStr(average);
end;

must to be attached to the Button1's Event OnCLick, othrwise it does not work ....

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Label1: TLabel;
    Edit7: TEdit;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var sum,average:extended;
    s:string;
begin    sum:=strtofloat(edit1.text)+strtofloat(edit2.text)+strtofloat(edit3.text)+strtofloat(edit4.text)+strtofloat(edit5.text);
    average:=sum / 5;
    s:=floattostr(sum);
    edit6.Text:=s;
    s:=floattostr(average);
    edit7.Text:=s;
end;

end.
(*created by FlamingClaw  2010.02.24.Hungary*)

I hope this helps

Hi FlamingClaw,

Long time no see, how are you?

Thank you for your help but it does not work as well.

Cheers,

I made the solution, look at that:

(*

this is your sum button :

procedure TForm1.Button1Click(Sender: TObject);
var
  sum, average: integer;
begin
  sum:=StrToInt(Edit1.Text)+StrToInt(Edit2.Text)+StrToInt(Edit3.Text)+
  StrToInt(Edit4.Text)+StrToInt(Edit5.Text);
  average:=sum div 5;
  Edit6.Text:=IntToStr(sum);
  Edit7.Text:=IntToStr(average);
end;

average and sum are local variables,put them global,then all buttons can reach them
you can disable the average button so it will reachable when the sum button pressed.
*)
unit Example3;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Button1: TButton;
    Button2: TButton;
    Edit6: TEdit;
    Edit7: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  sum, average: integer;   (*here are your variables,in the global section*)

implementation

{$R *.dfm}

(*the user must be press it first*)
procedure TForm1.Button1Click(Sender: TObject);
begin
  sum:=StrToInt(Edit1.Text)+StrToInt(Edit2.Text)+StrToInt(Edit3.Text)+
  StrToInt(Edit4.Text)+StrToInt(Edit5.Text);
  Edit6.Text:=IntToStr(sum);
  button2.Enabled:=true;
end;


(*counts the average of the sum,but it cannot be pressed while sum button set it enable*)
procedure TForm1.Button2Click(Sender: TObject);
begin
  average:=sum div 5;
  Edit7.Text:=IntToStr(average);
end;

(*here disable the button2,when the main form shows itself*)
procedure TForm1.FormShow(Sender: TObject);
begin
  edit6.Text:='';
  edit7.Text:='';
  button2.Enabled:=false;
end;

end.
(*fixed by FlamingClaw 2010.02.25.Hungary*)

I hope this helps

Hi,

I found that Delphi6 is not suitable to work on these exercises. Could you tell me what software(s) is / are suitable?

Cheers,

Sorry Sir,

The result is the same. It does not help.

Cheers,

I working under windows 7.Programming with borland Pascal 7.0 and delphi 7.My code is working well.

turbomen,
Could you explain, why in your Example3.zip the method procedure TForm1.Button1Click(Sender: TObject); is not assigned with the Event of Button1 OnClick ?
This is the reason your example does not work at all ....
I did upload here my example which works fine some days ago ....
May be you did not try it ?
Gud luck :!:

turbomen,
Could you explain, why in your Example3.zip the method procedure TForm1.Button1Click(Sender: TObject); is not assigned with the Event of Button1 OnClick ?
This is the reason your example does not work at all ....
I did upload here my example which works fine some days ago ....
May be you did not try it ?
Gud luck :!:

Dear Sir,

How can I use a For loop and a TImage components to produce the animation?

I need your help,

Cheers,

Your project works fine after I did remove a line from TonyProject1.dpr

Your project works fine after I did remove a line from TonyProject1.dpr

Thank you for your kind reply but could you tell me how can I change to For Loop?

Cheers,

Download the project below, it works using a For Loop:

TO show the result better use TLabel than using TEdit... It will work...

Use TLabel to display the result than using TEdit...
TLabel.caption:=inttostr(sum);

Use TLabel to display the result than using TEdit...
TLabel.caption:=inttostr(sum);

Do you mean about another project, different from project about animation ?

Below is an example ProjectSum about For loop using Edits and Labels:

Below is an example ProjectSum about For loop using Edits and Labels:

Thank you for your help at the last time. I have tried to re-do the question by myself. Could you tell me what is wrong or missing for the attached document?

Cheers,

Thank you for your help at the last time. I have tried to re-do the question by myself. Could you tell me what is wrong or missing for the attached document?

Cheers,

The following code is from your attached document:

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  count: integer; { this variable is declared on a wrong place }

procedure TForm1.Button1Click(Sender: TObject);
{ Here is missing a declaration about variable count: integer; }
begin
  { Here is missing a FOR loop using the variable count }
  Image1.Picture.LoadFromFile('T'+ IntToStr(count)+'.bmp');
  sleep(100);
  update;
  { Here is missing an end about FOR loop }
end;

{ Here is missing a method Button2Click }

end.

Dear Sir,

Thank you for your kind help and I have a new question. I have followed the demo to do the same thing but it does not work.

Please help me to have a look.

Cheers,

You can not use "sum" as a variable, as it is a Delphi assigned procedure, just change the name of your variable and it should work.

Soryy,
but it is not fair to answer so many different questions in one thread.
Every diffrerent question must to be asked in a new thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.