Forum > General
Shared Data between Classes
(1/1)
Weitentaaal:
Hello,
I'm facing an issue regarding Shared Data Fields. Let's hope I can explain it briefly:
I Have a Super Class and many Sub Classes. Then i have 2 Groups of which those Objects can be Part of.
However some of those Objects can be Part of both Groups. Those Objects have Data for Example Color.
The Color in group a Can be different than in group b.
I don't want to end up like this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- TSuper = class Color: TColor; end; TSub = class ColorForA: TColor; ColorForB: TColor; end;
howardpc:
If a subclass is part of both group A and group B what is your algorithm for determining what color the subclass should be in relation to the colors of groups A and B?
KodeZwerg:
Maybe by indexing?
bpranoto:
Make the group as a class and move the color field into class TGroup
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- TGroup = class Color:TColor; end; TSuper = class Group : TGroup; end; TSub = class // Access the color in Group Field end;
Thaddy:
Sharing data amongst controls is quite easy, but what you really ask is a contradiction in terms: It is not the same data:
--- Quote ---The Color in group a Can be different than in group b.
--- End quote ---
That means it must at least be a copy of any initial data...
Whereas the title suggests the same data...?
So what is it?
E.g. assigning one TStrings descendant instance to both a combobox items and a listbox items or a memo lines is sharing the same data.
Changing one will change the other too. Otherwise you need a copy. IOW a real copy vs a pointer copy.
This issue is known in computer science as deep vs shallow copy.
Navigation
[0] Message Index