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

changing properties of multiple components... 3

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
0
0
US
I have a lot of spinedit and was wondering if it possible to modify their properties a better way than i am doing.

right now i have:
square001.readonly := true;
....
Square100.readonly := true;

So i have 100 lines..Anyway to have a smarter method to do that?
Thanks.
P
 
@majlumbo
you said:
"My understanding was that you wanted an easy way to know the sequence number of your spinedits.."

I do not think this is what i am trying to achieve.
I have 101 spinedits and i want them to share the same event. For example the onclick event.

Like that i do not have to create an different onclick event for each spinedit.

Right now the onclick event for spinedit square001 is:
square001.value := x;

What i would like is to replace square001 with a variable that points to square001 or square002.....

Am i making sense or your explnations above explain that and i am really slow to understand.
P
 
Sorry that I misunderstood your previous post..

OK, another approach:

You should probably share the OnChange, not the OnClick event (user may change the value of your spinedit by other means than the mouse).

On your first spinedit double click the OnChange event, to create the method stub.

You should now have a procedure added to your form's declaration (SpinEdit1Change),

Add a new method to the private section, DoSomething passing the spinedit as a parameter.

Add a new variable to the private section that is a TSpinEdit.

In OnChange method, set the Activespinedit variable to the spinedit that called the OnChange Method. Then Call the DoSomething Method passing that spinedit.

In your object inspector, set ALL the other spinedits onChange event to point to the same SpinEdit1Change, instead of creating a new one. Clicking where the method name is, drops down a list of methods you can select from, select SpinEdit1Change...

Now all your spinEdits, will execute SpinEdit1Change when changed, and your onChange should be able to figure out which spinedit was the active component.

Code:
Form1 = class(TForm)
   procedure SpinEdit1Change(Sender: TObject);
private
   ActiveSpinEdit: TSpinEdit;
   procedure DoSomething(SE: TSpinEdit);
end;

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
   ActiveSpinEdit := TSpinEdit(Sender);
   DoSomething(ActiveSpinEdit);
end;


procedure TForm1.DoSomething(SE: TSpinEdit);
begin
   SE.<property> := <newValue>;
end;

Also, very important, do not change the value of your spin edit within the OnChange or DoSomething. It will start an infinite loop going.
 
Small Change (Again, I don't have Delphi here to test)

procedure TForm1.DoSomething(SE: TSpinEdit);
begin
<SomeValue> := SE.Value;
end;
 
Awesome...just want i needed. I did indeed use the onchange event. i also had to pass one extra parameters to the dosomething procedure.

It looks like it is behaving correctly.
appreciate your time. Now i know a little bit more about Delphi.
P
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top