Forum > Beginners
FPOObservedChanged
AlexTP:
In my app, I use class for Tag prop:
--- 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";}};} ---type TMyTag = class public SomeVal1, SomeVal2, SomeVal3: SomeTypes; end; begin Edit1.Tag:= PntInt( TMyTag.Create(Val1, Val2, Val3) );
Weitentaaal:
--- Quote from: Alextp on December 02, 2021, 01:21:14 pm ---In my app, I use class for Tag prop:
--- 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";}};} ---type TMyTag = class public SomeVal1, SomeVal2, SomeVal3: SomeTypes; end; begin Edit1.Tag:= PntInt( TMyTag.Create(Val1, Val2, Val3) );
--- End quote ---
This will work! Thank you @Alextp
How do you do your updates ?
jamie:
Why don't you point the same OnChange event to all the EDITS ?
In the OI you create just one and all remaining edits can point to the same OnChange event, just scroll down in the OI event creator and select it.
You can examine the Sender there to determine which edit it is, especially if it's in the same unit and class..
If Sender = Edit1 Then etc..
Weitentaaal:
--- Quote from: jamie on December 02, 2021, 01:36:06 pm ---Why don't you point the same OnChange event to all the EDITS ?
In the OI you create just one and all remaining edits can point to the same OnChange event, just scroll down in the OI event creator and select it.
You can examine the Sender there to determine which edit it is, especially if it's in the same unit and class..
If Sender = Edit1 Then etc..
--- End quote ---
I can and i did. But all i do in this Event Handlers are Graphical Changes, because i wanted to Split GUI and Logic. So i have 2 Classes, 1 Form and 1 Logic Class. I strgugle with informing my Logic class about the Changes on my GUI and with Updating my View with my Data from the Logic class. Thats why i wanted to create Some Observers to do what i wanted. With your Solution im back where i was at the begining with a realy messy Code.
Don't get me wrong... everything is working i just want to optimizie my Code for Maintenance and readability
Thaddy:
You can also do without tag, but with the IInterfaceComponentReference interface from TComponent. That will really decouple your code as long as it is Tcomponent derived.
See https://www.freepascal.org/docs-html/rtl/classes/iinterfacecomponentreference.html
Simplest example:
--- 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";}};} ---program compref; {$mode delphi}uses classes,sysutils;type TMyComponent = class(Tcomponent) end;var ref:IInterfaceComponentReference;begin ref := TMyComponent.Create(nil) as IInterfaceComponentReference; writeln('it is not a TComponent, but a TMyComponent!: ',(ref as TComponent).ClassName); end.Since you now can get at the ClassType, you can create further instances of the correct type in the gui part from the TClass.classtype reference.
This code has a small leak, but it just shows the principle.
As you can see the code is fully decoupled as long it is a Tcomponent derivative.
I mean the generic code can be simply
(ref as TComponent).ClassName
and (ref as TComponent).classtype
The latter being a TClass from which you can create more instances of the same type.
All components support this interface so there is no reason to mis-use tag.
E.g. (ref as TComponent).classtype would return class of TEdit for TEdit etc.
Navigation
[0] Message Index
[*] Previous page