Working with external programs
You can run an external program in PowerBuilder by calling functions
Windows API CreateProcess (Ex) or ShellExecute (Ex) (the second function may not
only run executable files, but also run applications associated with
documents). You can, of course, use the standard PowerBuilder
Run ( "Program name" , windowstate) ,
but the most you can manage with
this approach is the size of the window at the start of the program. Much more practical
use the above functions (ShellExecuteEx implementation is in
library WinAPI ).
Using the ShellExecuteEx function to run the program, you get it
header (handle). Further, using it as a parameter for the functions
TerminateProcess or GetExitProcessCode you can terminate the program
or to check if the program is still running (there are a number of other functions for
work with external programs, but you should read about this in the documentation
Microsoft), in addition, you can send messages to the created application.
How to dynamically change the menu
Example of generating a menu level:
menu mi, m
m = create menu
for li_item = 1
to UpperBound (as_items []) /
2
// array with menu names and their tags
// menu items are a single-item menu created in painter,
// with a clicked script that determines what to do by tag
mi = create m_dyn_menu_item
m.item [li_item] = mi.item [ 1 ] .item [
1 ] // like this :))
m.item [li_item] .text = as_items [li_item * 2 -
1 ]
m.item [li_item] .tag = as_items [li_item * 2 ]
next
// replace submenu number n with a new one
// if n = UpperBound (m_mdi.item []) + 1 then the menu item is added to the end.
m_mdi.item [n] = m
m_mdi.item [n] .Hide ()
m_mdi.item [n] .Show ()
From: "Anatoly Moskovsky"
avm@trais.com.ua
How can I install / get the list of libraries used by the program.
This can be done using the SetLibraryList (...) function.
Naturally, this function must be called before accessing objects.
from the libraries you are going to add with SetLibraryList (...).
Addition.
In order to get a list of libraries used by the program, you can
use the GetLibraryList (...) function, but this is only suitable for
PowerBulider version 7.0+. In earlier versions, you can use the following
code:
string LibList = ProfileString (
"pb.ini" ,
"Application" ,
"$ d: \ pbuilder \ pb6 \ appgal \ CashTrak \ cashtrak.pbl (CashTrack)"
)
The value of the ProfileString (...) function will be calculated for the LibList variable
at compile time. It remains only to parse the LibList string for selection
libraries.
Addon From: "Andrew Zorin"
azorin@online.ru
Dynamically reorder groups in a report.
I know of at least four approaches for solving this problem:
1. Dynamic generation of requests from the client with the necessary conditions.
This method is very laborious, and in addition to everything, it "ties" a certain
the kind of agreement (for example, on the structure of the base), but the end result
can be quite good, in addition, you can not only be limited to
changing the order of groups in the report.
2. Changing the syntax of DataWindow.
Works reasonably fast, but as you know, DataWindow syntax is not
documented, which gives rise to additional difficulties and possible problems with
portability of the program to other versions of PowerBuilder. Moreover, this
the method requires an additional DataWindow or DataStore to store the results
while the syntax of the main DataWindow changes. The advantage of this method is
the fact that you can create more groups than provided in Design Time.
3. Setting up surrogate fields for grouping.
The idea is quite simple - to add additional fields (let's call them
ID1, ID2, ..., IDn), equal to the number of report groups and create groups
precisely along these fields and further, fill them with increasing values from the same
the sequence in which to group. A few tips for
implementation. First, dynamically scramble the string and set the sort to
the order in which you want to group, something like:
dw_1.SetSort ( "field_3 A field_1 A field_2 A" )
dw_1.Sort ()
After that, it will be enough to run through all lines dw_1 (or once
all field_1..field_n, or run n times, but in each pass only
one field_i - to taste) increasing some internal counters
changes of fields field_1..field_n with each encountered change of fields
and enter their values into ID1..IDn, respectively. Then put
sorting by fields ID1..IDn. The entire implementation takes, at most, 40-50 lines.
4. Groups can be defined by computed fields. So
way, one can simply define the group by the calculated field and then
change its expression.
The fourth method From: "Andrew Zorin"
azorin@online.ru
Printing and viewing HTML using Windows.
HTML viewing is achieved by calling the ShellExecuteEx function with
with the following values of the SHELLEXECUTEINFO structure attributes:
SEI.lpfile = "C: \ MYPATH \ myfile.htm"
To do this, you need to install some kind of HTML file viewer.
And print:
SEI.lpfile = "rundll32.exe"
SEI.lpparameters = "MSHTML.DLL, PrintHTML
C: \ MYPATH \ myfile.htm "
this invokes Internet Explorer's print dialog. Naturally,
it must first be installed on the machine. Windows function implementation
The SchellExecuteEx API is available in the WinAPI library.
How to get DWObject for columns DataWindow.
For PB 6:
DWObject dwo
dwo = dw_1.object.get_attribute (
"column_name" , True )
For PB 7, 8 and 9:
dwo = dw_1.object .__ get_attribute (
"column_name" , True )
From: "Anatoly Moskovsky"
avm@trais.com.ua
| Column # | Data | Text |
|---|---|---|
| 1 | colname | textname |
| 2 | colname_1 | textname_1_t |
| 3 | colname_2 | textname_2_t |
| 4 | colname_3 | textname_3_t |
| 5 | colname_4 | textname_4_t |
| ... | ... | ... |