Handle

Hello Everyone, hope you are doing great. I am feeling very lucky to join this group.

Basically i am unable to understand the basic use of Handle/Widget-Handle/Com-Handle(Types) and what are the scenarios where we are using them, could anyone help me out of it.

Thanks!!!
 

TomBascom

Curmudgeon
Handle based objects need to be explicitly created, manipulated and, most importantly, destroyed by the programmer.

First you define a variable for the handle.

Then you create the object and assign it to that handle.

After it has been created you set attributes and execute methods to accomplish whatever purpose you had for creating it.

If you create it, you must also eventually destroy it. Failure to do so is what causes memory leaks. A very large percentage of the problems that arise in handle based programming, especially when you are just starting out, are a result of neglecting to delete objects properly.
 

jongpau

Member
A handle is a "pointer" to an object (UI object, temp-table, prodataset, server etc). I do not think there is much difference between a HANDLE and a WIDGET-HANDLE. You can safely use a HANDLE variable for a WIDGET type object. A COM-HANDLE however is a special type of handle that is used in combination with ActiveX and OCX controls.

Additionally to what Tom said, you can also use handles to access properties and methods on a lot of objects (not all) that are defined in your code rather created at run-time. Contrary to objects that you create dynamically you do not have to (= cannot) explicitly destroy objects that you define as OpenEdge will do that for you automatically. You can however still use their handle similar to using a handle of a dynamic object.

For instance when using temp-tables, you can dynamically create a temp-table with CREATE TEMP-TABLE and assign the handle; this is the scenario where you need to make sure you destroy the object when you no longer need it. Alternatively you can define a temp-table with DEFINE TEMP-TABLE and get its handle with TEMP-TABLE <NAME>:HANDLE. Most of the properties and methods available to dynamic objects are also available on their static counterparts.

Handles and objects are a bit of a dark art for some, but once you get the hang of them they can be very powerful and allow you to do some pretty cool stuff :)
 

GregTomkins

Active Member
Use handles to create something whose details are only knowable at run-time. For example, you could create a TEMP-TABLE (sort of like a ADO RecordSet, if you are from .NET) with fields that are determined based on some input that happens at run-time.

Contrast this with static TEMP-TABLEs, whose fields are baked into the code at compile time.

The same idea applies to most things in Progress, eg. buffers, temp-tables, widgets (but notably, not to variables).

Though perhaps there is some matter of opinion here, I'd say handles are much more flexible, at the cost of a higher possibility of run-time errors. You could argue that handles are more verbose and harder to understand, but the former is definitely not always true (the polar opposite is often true) and the latter is really just a matter of familiarity.

Some people love handles, some are terrified of them. My personal opinion is that they're great but should be reserved for situations like I described above, and static should otherwise be preferred. But that's just my opinion!
 
Hello Everyone, hope you all are Well. :)

As per above description i started working with handles and have further concerns regarding handles:

1. We can use Static object without using handles but we have to use handles if we use dynamic objects, then why to associate handle with dynamic object because most of the properties and methods are accessed via static objects also and primary purpose of handle is to use methods and properties of a object and this object is either static or dynamic(Is it because memory location of dynamic object is not known at run time?).

2. I want to know the memory representation of handle for ex: If handle is like a pointer then it takes space in memory(RAM) pointing to object which is also in RAM or HD and does this representation is same for static and dynamic object?

3. I want to create a list of Handle based objects with respective properties and methods, how could i do that?

Perhaps, my questions are too generic to ask but i stuck there. :(

Thanks & Regards!
Rajat.
 

TomBascom

Curmudgeon
1) That is correct. A dynamic object's memory location is not established until you create it at runtime.

2) You can think of a handle as being analgous to a pointer like you might find in C. The actual memory representation is not documented. But it is probably similar. I'm just guessing though -- I have no special knowledge about it.

3) "Walk the widget tree."
 

GregTomkins

Active Member
"then why to associate handle with dynamic object because most of the properties and methods are accessed via static objects"

We use these scenarios a lot:

1. You have a program loaded with business logic to do something like route orders or calculate interest. It needs to be intimately aware of the details of (say) temp-table records. It would typically use static references only.

2. This program calls another program that is generic in nature. Eg., we have a little helper called 'show_dynamic_temp_table.p' that takes any table and spews all its field values out into a log file. This uses dynamic references, so it will always work for any table, even ones I newly create a year from now, without changes.

Progress lets you use the same table in both situations without having to do anything nasty like make another copy of it in the other format. This is one of my favorite things about Progress.

Same idea applies with dynamic GUI widgets and DB buffers.
 

Attachments

  • upload_2014-6-5_12-31-33.png
    upload_2014-6-5_12-31-33.png
    243.9 KB · Views: 20

Cringer

ProgressTalk.com Moderator
Staff member
There is a massive list of reasons why you might want to use dynamic objects. If you can use static then that is probably a lot easier to design and maintain, but sometimes this is impossible.
For example, I have a program where the user drops an excel sheet onto a browse for import. The excel sheet can have an arbitrary format. I build a dynamic browse from the data in the spreadsheet. They then decided they may also want to manually add some extra records to the data after they imported the sheet. So I added dynamic widgets based on the structure of the excel sheet allowing them to add records. When the program is loaded it just has a couple of buttons and a place-holder browse that are static. The rest is, by design, all done dynamically.
It's a good idea to have a play around with dynamic objects to become fluent in their use, because you will find they are incredibly useful in a lot of scenarios.
I've attached a small program I wrote that is a battleships game that uses a lot of dynamic objects. You'll have to faff about with the images to get it to run (Change the ImagePath preprocessor to wherever you put the images). It's not the most elegant code as I wrote it a long time ago, but it might help you to see what you can do with dynamic objects.
 

Attachments

  • SinkEm.w
    55.2 KB · Views: 30
  • images.zip
    679 bytes · Views: 25

Cecil

19+ years progress programming and still learning.
I've attached a small program I wrote that is a battleships game that uses a lot of dynamic objects. You'll have to faff about with the images to get it to run (Change the ImagePath preprocessor to wherever you put the images). It's not the most elegant code as I wrote it a long time ago, but it might help you to see what you can do with dynamic objects.

dbview.i missing Doh.!
 

Cringer

ProgressTalk.com Moderator
Staff member
Yeah there's 2 includes missing. You can take them out of the code.
 

Cecil

19+ years progress programming and still learning.
Yeah there's 2 includes missing. You can take them out of the code.
Well that was a bit of five minute fun. I remember somebody did a tetris game years ago 8.1C. I remember hooking it up to a retail customer LED display to keep track of the score. Good old days.
 

Cringer

ProgressTalk.com Moderator
Staff member
dbview is a tool that Martin Allen wrote, similar to ProTop. He had a roulette game in there and someone did space invaders style game too. I wrote a few games for it: A hangman game, that battleships game, and a draughts game. The AI for draughts needs some work as it just takes random valid moves, but the functionality is all there.
 
Top