Solved

Howto: Updating a TEdit component?

Posted on 2000-03-18
7
256 Views
Last Modified: 2010-04-04
Hi experts,

I have a program with these components: 1 form, 1 Tedit and 3 TCheckboxes

I connected the three checkboxes with the figures "5" ,"3" and "7" .

Now I want to achieve that the Tedit displays the status (selected/not selected)
of the checkboxes.

For example if the checkbox with the "1" and the checkbox with the "3" are clicked",
the TEdit should display the figure "4", because 1+3 = 4.

The TEdit should be always updated, whenever I make a mouse-click on one of the 3
checkboxes.

Has anyone of you an idea, how this could be accomplished?

With kind regards

Mathes
0
Comment
Question by:mathes
  • 4
  • 2
7 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 2630944
hi mathes,

what about this?

const Multipler : Array[False..True] of Integer = (0,1);

//this procedure is assigned to all checkbox.Onclick-event
procedure TForm1.CheckBox1Click(Sender: TObject);
var I : Integer;
begin
  I := (1 * Multipler[Checkbox1.checked]) +
       (2 * Multipler[Checkbox2.checked]) +
       (3 * Multipler[Checkbox3.checked]) +
       (4 * Multipler[Checkbox4.checked]);
  edit1.text := IntToStr(I);
end;

meikl
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2630945

set onClick event for all checkboxes to CheckBox1Clik1
{
CheckBox1.onClick = CheckBox1Click
CheckBox2.onClick = CheckBox1Click
CheckBox3.onClick = CheckBox1Click
}

procedure TForm1.CheckBox1Click(Sender: TObject);
var SUM : integer;
begin
     SUM:=0;
     if CheckBox1.Checked then SUM:=StrToInt(CheckBox1.Caption);    
     if CheckBox2.Checked then SUM:=SUM+StrToInt(CheckBox2.Caption);    
     if CheckBox3.Checked then SUM:=SUM+StrToInt(CheckBox3.Caption);    
     Edit1.Text:=IntToStr(SUM);
end;

Cheers,
Igor.

PS: Captions (figures) on checkbox must be able to convert to numeric value.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2630946

set onClick event for all checkboxes to CheckBox1Clik1
{
CheckBox1.onClick = CheckBox1Click
CheckBox2.onClick = CheckBox1Click
CheckBox3.onClick = CheckBox1Click
}

procedure TForm1.CheckBox1Click(Sender: TObject);
var SUM : integer;
begin
     SUM:=0;
     if CheckBox1.Checked then SUM:=StrToInt(CheckBox1.Caption);    
     if CheckBox2.Checked then SUM:=SUM+StrToInt(CheckBox1.Caption);    
     if CheckBox3.Checked then SUM:=SUM+StrToInt(CheckBox1.Caption);    
     Edit1.Text:=IntToStr(SUM);
end;

Cheers,
Igor.

PS: Captions (figures) on checkbox must be able to convert to numeric value.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 9

Expert Comment

by:ITugay
ID: 2630948
Good morning, Meikl!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2631013
hi igor ;-)
where are you from?


hi mathes,

more independent, based on my first sample

const Multipler : Array[False..True] of Integer = (0,1);

//all checkboxes now on a panel for better iterating
//and the Checkbox-Caption holds the value, which should added
//this procedure is assigned to all checkbox.Onclick-event
procedure TForm1.CheckBox1Click(Sender: TObject);
var I,J : Integer;
begin
  I := 0;
  for j := 0 to panel1.ControlCount - 1 do
    if (panel1.Controls[J] is TCheckBox) then
      I := I + (StrToInt(TCheckBox(panel1.Controls[J]).Caption) *
                Multipler[TCheckBox(panel1.Controls[J]).Checked]);
  edit1.text := IntToStr(I);
end;

meikl
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2631024
Hi Meikl,
I'm from Almaty (GMT+6).
You can mail me igor@novell.kz
or call (7) 300-711-6527 (cell ;-)

0
 

Author Comment

by:mathes
ID: 2632709
Hi experts,

thank you for your help. This is exactly what I was looking for.

With kind regards

Mathes
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Print Graphic and Text to Epson TM-T88v 12 378
Delphi inherited method 6 76
Delphi: Connect to running MS Outlook 4 118
Tembedded WB animatid gifs not animated on some pcs 2 84
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question