From: phil hunt on
It sounds too much like work. Maybe some other time. But I am curious what
you mean by 'factory'. I came across them in some other language, but not
VB6

"ralph" <nt_consulting64(a)yahoo.net> wrote in message
news:4fe166538h1e7enblsfdm460dgfjaa1bs6(a)4ax.com...
> On Mon, 09 Aug 2010 21:28:53 -0500, ralph <nt_consulting64(a)yahoo.net>
> wrote:
>
>>On Mon, 9 Aug 2010 21:41:28 -0400, "phil hunt" <a(a)abc.com> wrote:
>>
>>>I am more interested in the data. As I am changing data, I want to 'undo'
>>>the change just by reverting back to the clone.
>>>
>>>
>>
>
> Another strategy that is occasionally useful, is based on a timeless
> principle of programming: "There is no problem that can't be resolve
> with another layer of indirection". <g>
>
> Wrap your object with one that combines a factory with storage.
>
> -ralph


From: ralph on
On Mon, 9 Aug 2010 23:45:37 -0400, "phil hunt" <a(a)abc.com> wrote:

>It sounds too much like work. Maybe some other time. But I am curious what
>you mean by 'factory'. I came across them in some other language, but not
>VB6
>

A Factory pattern/method is where you define an interface for creating
an object, and then let it decide who and what to create. In your case
also providing a Proxy - a surrogate to control access to the object/s
created. eg, swapping out objects with the client being none the
wiser.

Factory (and Proxy) are what is called 'Design Patterns'. A way of
describing general reuseable software architecture.

http://en.wikipedia.org/wiki/Design_pattern_(computer_science)
and
http://en.wikipedia.org/wiki/Factory_method_pattern

A Factory/Proxy in this case, would be a mechanism to simply store
whole objects instead of serializing them.

-ralph
From: Jason Keats on
phil hunt wrote:
> I am more interested in the data. As I am changing data, I want to 'undo'
> the change just by reverting back to the clone.


If you want to ignore all changes to your object, then the easiest thing
to do is simply throw it away and reload it from the database.

Cloning would probably mean you have to write code to serialise and
deserialise your object's state (unless you use Ralph's suggestion of
saving the ADO recordset you used to populate your object, to XML).

If, however, you needed to keep track of changes to each property - so
you can undo undo changes one property at a time - then you probably
want to keep a LIFO stack containing your changes.

Many use code generation (eg one class per table) to solve this sort of
problem, especially if similar code is required for many classes.
From: Nobody on
"Phil Hunt" <aaa(a)aaa.com> wrote in message
news:%2333oQjBOLHA.4824(a)TK2MSFTNGP05.phx.gbl...
>I have a simple object I load up from DB, Is there a easy way to clone it
>to a new object of the same type ?

MZTools lists all properties of your classes when you use "Generate XML
Documentation". You need to copy them to Excel or similar program to extract
property names.

Also, the code below dumps a list of properties, methods, and events of your
class from Object Browser, so you can easily write code to save the
contents. It uses SendKeys and copy from the Clipboard. To use it, bring up
Object Browser(F2), then select your project name from the list, then click
on your class. You would see the list of properties on the right pan. Right
click anywhere and make sure that "Group Members" is selected. Click on the
first property on the right pan, then start a new VB IDE instance, add a
Timer to Form1, then add the code below. Run the project, and switch to the
VB IDE that is showing Object Browser. After 5 seconds, the running program
would capture property names and print them to the immediate window. From
there, you can copy them and do with them whatever you want.

Option Explicit

Private Sub Form_Load()
Timer1.Interval = 5000
End Sub

Private Sub Timer1_Timer()
Timer1.Enabled = False
DumpObjectBrowser
End Sub

Private Sub DumpObjectBrowser()
Dim Str As String
Dim LastStr As String
Dim Counter As Long

Clipboard.Clear
Counter = 0
Do
LastStr = Str
SendKeys "^c", True
Delay 0.1
Str = Clipboard.GetText
If LastStr = Str Then
' We reached the end
Exit Do
End If
Debug.Print Str
SendKeys "{DOWN}", True
Delay 0.1
Counter = Counter + 1
Loop Until Counter = 100
Me.Caption = "Done!"
End Sub

Private Sub Delay(ByVal Seconds As Single)
Dim t As Single

t = Timer
Do While Abs(Timer - t) < Seconds
DoEvents
Loop
End Sub



From: Phil Hunt on
Intersting.
I am thinking about cloning the data, not the definition.
It is academic now. But can I use a Property bag in my situation. I seen it,
but never play with it.


"Nobody" <nobody(a)nobody.com> wrote in message
news:i3rmlh$c7r$1(a)speranza.aioe.org...
> "Phil Hunt" <aaa(a)aaa.com> wrote in message
> news:%2333oQjBOLHA.4824(a)TK2MSFTNGP05.phx.gbl...
>>I have a simple object I load up from DB, Is there a easy way to clone it
>>to a new object of the same type ?
>
> MZTools lists all properties of your classes when you use "Generate XML
> Documentation". You need to copy them to Excel or similar program to
> extract property names.
>
> Also, the code below dumps a list of properties, methods, and events of
> your class from Object Browser, so you can easily write code to save the
> contents. It uses SendKeys and copy from the Clipboard. To use it, bring
> up Object Browser(F2), then select your project name from the list, then
> click on your class. You would see the list of properties on the right
> pan. Right click anywhere and make sure that "Group Members" is selected.
> Click on the first property on the right pan, then start a new VB IDE
> instance, add a Timer to Form1, then add the code below. Run the project,
> and switch to the VB IDE that is showing Object Browser. After 5 seconds,
> the running program would capture property names and print them to the
> immediate window. From there, you can copy them and do with them whatever
> you want.
>
> Option Explicit
>
> Private Sub Form_Load()
> Timer1.Interval = 5000
> End Sub
>
> Private Sub Timer1_Timer()
> Timer1.Enabled = False
> DumpObjectBrowser
> End Sub
>
> Private Sub DumpObjectBrowser()
> Dim Str As String
> Dim LastStr As String
> Dim Counter As Long
>
> Clipboard.Clear
> Counter = 0
> Do
> LastStr = Str
> SendKeys "^c", True
> Delay 0.1
> Str = Clipboard.GetText
> If LastStr = Str Then
> ' We reached the end
> Exit Do
> End If
> Debug.Print Str
> SendKeys "{DOWN}", True
> Delay 0.1
> Counter = Counter + 1
> Loop Until Counter = 100
> Me.Caption = "Done!"
> End Sub
>
> Private Sub Delay(ByVal Seconds As Single)
> Dim t As Single
>
> t = Timer
> Do While Abs(Timer - t) < Seconds
> DoEvents
> Loop
> End Sub
>
>
>