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!

Setall is not work in class control 1

Status
Not open for further replies.

lardecristo

Programmer
Sep 8, 2012
9
BR
I read this thread, and I like it... :)

But, I have problem for this method in my class.

I make a class Control and put in 4 objects.

1 - Command
1 - Container
and beside the container 2 Lines

in Command1.Click this code.
THIS.Parent.Container1.SetAll("BorderColor", RGB(255,0,0), "Line")

but this code don´t execute.

When I change Class Control to Class Container, this code run OK.

Code:
DEFINE CLASS teste AS control


	Width = 65
	Height = 416
	Name = "teste"


	ADD OBJECT line1 AS line WITH ;
		Height = 181, ;
		Left = 7, ;
		Top = 18, ;
		Width = 1, ;
		Name = "Line1"


	ADD OBJECT line2 AS line WITH ;
		Height = 195, ;
		Left = 38, ;
		Top = 6, ;
		Width = 9, ;
		Name = "Line2"


	ADD OBJECT container1 AS container WITH ;
		Top = 205, ;
		Left = 3, ;
		Width = 59, ;
		Height = 200, ;
		Name = "Container1"


	ADD OBJECT teste.container1.line1 AS line WITH ;
		Height = 181, ;
		Left = 7, ;
		Top = 14, ;
		Width = 1, ;
		Name = "Line1"


	ADD OBJECT teste.container1.line2 AS line WITH ;
		Height = 195, ;
		Left = 38, ;
		Top = 2, ;
		Width = 9, ;
		Name = "Line2"


	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 62, ;
		Left = 12, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Command1", ;
		Name = "Command1"


	PROCEDURE command1.Click
		THIS.Parent.Container1.SetAll("BorderColor", RGB(255,0,0), "Line")
	ENDPROC


ENDDEFINE
 
Objects of a control class are protected. I guess you know that and want to use that?
The Setall() call should work, as command1 and container1 are part of the control and this means protected elements of a class access each other, which is fine.

What demonstrates that this protected access works in principle is
Code:
	PROCEDURE command1.Click
		THIS.Parent.Container1.Line1.BorderColor=RGB(255,0,0)
		THIS.Parent.Container1.Line2.BorderColor=RGB(255,0,0)
	ENDPROC
But Setall does not work for me, too. And this verbose solution is too cumbersome to do with more lines.

I'd conclude: It's better to not use the control class as a basis, but the container. The only thing you don't have is the protection of the inner objects, but it's not worth the struggles you have even of internal code staying within the encapsulation of the class.

Chriss
 
The following note from the VFP Help will explain this further:

VFP Help said:
Control objects can contain other objects, but, unlike container objects, do not allow access to the objects contained within them. For example, if you create a control object that consists of two ListBoxes and two CommandButtons, and then add the control object to a form, the ListBoxes and CommandButtons cannot be manipulated individually at design time or at run time.

Also, SetAll is not listed as one of the Control object's methods, but that method is present for the Container object.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike Lewis said:
Also, SetAll is not listed as one of the Control object's methods, but that method is present for the Container object.

That's why lardecristo put a container into the control class and used the SetAll method of that container with This.Parent.Container1.SetAll(...)

Considering that accessing Container1 should work just as it works to access line1 and line2 directly, SetAll() should find the line objects and set their color. Setall() is not called from outside, the call comes from a button within the class, it's all staying in the encapsulation of the control.

I actually remember form.SetAll would violate the protection of objects inside it and set them in earlier VFP versions. It seems to me that violation was fixed, but the fix was too simple and now it seems the SetAll method is completely castrated to work on controls inside a class based on control.

Well, as said it's not really a well behaving base class. I recently also played with this base class and it seems to me what I'd call a final class, if you subclass a class based on control, it's not allowed to add further objects to it, which also makes it less useful.


Chriss
 
Hey guys, thanks for yours reply.

Chris Miller my class is complex, and my idea is expose less thing is possible.
CalendariodoMes.Data this is a property expose, but now I need run each one, property by property, method by method and change it. :(

But ok, I will change it to Container.

I discover .Controls or .Objects both not work too.
 
lardecristo said:
I discover .Controls or .Objects both not work too.

What works for me in teste.Command1.Click():
Code:
For Each loControl in This.Parent.Container1.Controls
    If PemStatus(loControl,"BorderColor",5)
       loControl.BorderColor = Rgb(255,0,0)
    EndIf
EndFor

I think the better solution is to base everything on the container class and be able to use SetAll instead of such a loop.

Chriss
 
Hi Chris, thank again.
I try your code, and work fine, but I need use the same in my original code, I will do this, next week.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top