I.T. Discussion Community!
-Collapse +Expand
Paradox
Search Paradox Group:

Advanced
-Collapse +Expand Paradox To/From
To/FromCODEGuides
-Collapse +Expand Paradox Store
PRESTWOODSTORE

Prestwood eMagazine

May Edition
Subscribe now! It's Free!
Enter your email:

   ► KBParadox Knowledge Base  Print This    Code Snippet DB All Groups  

Paradox Code Snippets Page

These Code Snippets are contributed by you (our online community members). They are organized by our knowledge base topics. Specifically, by the Paradox sub-topics.

Contribute a Code Snippet
Expand All

42 Corel Paradox / ObjectPAL Coding Code Snippets

Group: Corel Paradox / ObjectPAL Coding


Topic: Paradox & ObjectPAL

-Collapse +Expand 1. ObjectPAL Array (Array[] type)
 

Arrays in ObjectPAL use a 1-based indice.

Use size() to get the number of elements. size() returns 0 if the array has no elements.

var
  MyArray Array[4] String ;Fixed size array.
  i LongInt
endVar

MyArray[1] = "Mike"
MyArray[2] = "Lisa"
MyArray[3] = "Felicia"
MyArray[4] = "Nathan"

if MyArray.size() > 0 then
  for i from 1 to MyArray.size()
    msgInfo("", MyArray[i])
  endFor
endIf

Posted By Mike Prestwood, Post #102138, KB Topic: Paradox & ObjectPAL



Topic: Installation, Setup, & BDE

-Collapse +Expand 2. ObjectPAL File Extensions
 

Paradox for Windows has two primary file types: source files and delivered files. Source files in Paradox are binary but can can be opened in later versions of Paradox and even in earlier versions if you don't use any new features: .FSL = Form, .RSL = Report, .SSL = Script, and .LSL = Library. Since Paradox source files do not compile to an EXE, Paradox developers tend to use a startup form or script to start the application.

Posted By Mike Prestwood, Post #101354, KB Topic: Installation, Setup, & BDE



Topic: OPAL: Language Basics

-Collapse +Expand 3. ObjectPAL Assignment (=)
 

ObjectPAL uses = for it's assignment operator.

var
 FullName String
   Age SmallInt
endVar
  
FullName = "Randy Spitz"
Age = 42
Posted By Mike Prestwood, Post #101381, KB Topic: OPAL: Language Basics
-Collapse +Expand 4. ObjectPAL Case Sensitivity (No)
 

ObjectPAL is not case sensitive. My preference for ObjectPAL is to follow the camel casing promoted in the examples and help files originally developed by Borland.

All of the following are equivalent:

msgInfo "", "Hello"
MsgInfo "", "Hello"
msginfo "", "Hello"
MSGINFO "", "Hello"

Variables are not case sensitive.

Var
FullName String
endVar
fullname="Mike Prestwood"
msgInfo("", fullNAME)
Posted By Mike Prestwood, Post #101341, KB Topic: OPAL: Language Basics
-Collapse +Expand 5. ObjectPAL Code Blocks (endXxxx)
 

ObjectPAL code blocks are surrounded by statement ending keywords that all use End with camel caps such as endMethod, endVar, endIf, endSwitch, and endTry.

method
endMethod
 
var
endVar
 
if
endIf
 
switch
endSwitch
 
try
endTry
Posted By Mike Prestwood, Post #101495, KB Topic: OPAL: Language Basics
-Collapse +Expand 6. ObjectPAL Comments (; and { ... })
 

Commenting Code
ObjectPAL uses ; for a single line comment and { } for a multiple line comment.

;Single line comment.

{
Multiple line
comment.
}
Posted By Mike Prestwood, Post #101506, KB Topic: OPAL: Language Basics
-Collapse +Expand 7. ObjectPAL Comparison Operators (=, <>)
 

Common comparison operators:

= equal
<> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal

'Does ObjectPAL evaluate the math correctly? No!
If .1 + .1 + .1 = .3 Then
msgInfo("", "correct")
Else
msgInfo("", "not correct")
endIf
Posted By Mike Prestwood, Post #101875, KB Topic: OPAL: Language Basics
-Collapse +Expand 8. ObjectPAL Constants (const..endConst)
 

In ObjectPAL, you declare one or more constant values within a const..endConst block. Optionally, you can specify the dataType by casting the value as part of the declaration. If you do not specify the data type, the data type is inferred from the value as either a LongInt, a Number, a SmallInt, or a String. As with variables, the const..endConst block can come within a method or procedure as the first bit of code, or in the Const window. Putting it above the method or procedure is allowed but has no significance so don't.

const
kFeetToMeter = Number(3.2808)
kMeterToFeet = Number(.3048)
kName = String("Mike")
  kCA = "California"     ;String inferred.
endConst
Posted By Mike Prestwood, Post #101730, KB Topic: OPAL: Language Basics
-Collapse +Expand 9. ObjectPAL Development Tools
 

Corel Paradox for Windows (was Borland Paradox). Also, Borland used to offer a Paradox for DOS tool which support it's Paradox Application Language (PAL) which is not compatible with ObjectPAL. The biggest drawback to Paradox is that Corel does not have anyone at Corel actively developing Paradox for Windows (as opposed to Microsoft Access which does).

Posted By Mike Prestwood, Post #101550, KB Topic: OPAL: Language Basics
-Collapse +Expand 10. ObjectPAL Edit Record (insertRecord, postRecord, edit)
 

In ObjectPAL, you use Cursor.InsertRecord to add a new record, Cursor.postRecord to post the record, and Cursor.deleteRecord() to delete it. To edit a record, you must put the cursor into edit mode, Cursor.Edit(). (A cursor applies to both a TCursor and UIObject.)

ObjectPAL gives you tremendous flexibility with editing data and includes many additional commands such as insertAfterRecord and isEdit. For dBASE tables, you can also use unDeleteRecord() to un-delete a record. See the ObjectPAL help for more commands.

The following code snippet adds a record to a given TCursor with FullName and Created fields:

tc.edit()
tc.InsertRecord()
tc.FullName = "Barack Obama"
tc.Created  = today()
tc.postRecord
Posted By Mike Prestwood, Post #102112, KB Topic: OPAL: Language Basics
-Collapse +Expand 11. ObjectPAL Empty String Check (isBlank() or not isAssigned())
 

In ObjectPAL, an empty variable can be unassigned (essentially null) or blank (equivalent to ""). You have to use both isBlank and isAssigned to check for an empty string.

var
 s String
endVar
  
;s = ""  ;Uncomment to test 2nd case.
 
if isBlank(s) or not isAssigned(s) Then
 msgInfo("", "empty string")
endIf
Posted By Mike Prestwood, Post #102041, KB Topic: OPAL: Language Basics
-Collapse +Expand 12. ObjectPAL End of Statement (whitespace)
 

Languages Focus: End of Statement

In coding languages, common End of statement specifiers include a semicolon and return (others exist too). Also of concern when studying a language is can you put two statements on a single code line and can you break a single statement into two or more code lines.

ObjectPAL End of Statement

ObjectPAL is a bit unique in that it doesn't use a semicolon nor a return to mark the end of a line, it uses whitespace which can be a return, space, or tab. This is a bit unusual but does allow for some nice formatting of code.

msgInfo("", "Hello1")
msgInfo("", "Hello2")
msgInfo("", "Hello3")

;The following single line of code also works.
msgInfo("", "Hello4") msgInfo("", "Hello5")

;Two or more works too:
msgInfo
("", "Hello6")
Posted By Mike Prestwood, Post #101694, KB Topic: OPAL: Language Basics
-Collapse +Expand 13. ObjectPAL If Statement (If..Else..EndIf, or switch)
 

ObjectPAL supports a simple If...Else...EndIf statement.

Notice ObjectPAL does not support an ElseIf feature as part of an if statement. Instead use a switch statement

'Does ObjectPAL evaluate the math correctly? No!
If (.1 + .1 + .1) = .3 Then
  msgInfo("", "Correct")
Else
  msgInfo("", "Not correct")
EndIf
 
'Switch statement example.
switch
case x = "Nate": MsgInfo("", "Hi Nate")
case x = "Felicia": MsgInfo("", "Hi Felly")
  otherwise: MsgInfo("", "Who are you?")
endSwitch
Posted By Mike Prestwood, Post #101386, KB Topic: OPAL: Language Basics
-Collapse +Expand 14. ObjectPAL Literals (quote)
 

Literals are quoted as in "Prestwood".  If you need to embed a quote use a slash in front of the quote as in \"

In ObjectPAL, string literals are limited to 255 characters but there's nothing preventing you from using multiple string literals together as in:

msgInfo("", "Hi Mike: " + "You can add literals together in ObjectPAL")
msgInfo("", "Hello")
msgInfo("", "Hello \"Mike\".")
  
;Does ObjectPAL evaluate this simple
;floating point math correctly? No!
If (.1 + .1 + .1) = .3 Then
 msgInfo("", "Correct")
Else
 msgInfo("", "Not correct")
EndIf
Posted By Mike Prestwood, Post #101529, KB Topic: OPAL: Language Basics
-Collapse +Expand 15. ObjectPAL Logical Operators
 

ObjectPAL logical operators:

and and, as in this and that
or or, as in this or that
Not Not, as in Not This

;Given expressions a, b, c, and d:
if Not (a and b) and (c or d) then
  ;Do something.
endIf
Posted By Mike Prestwood, Post #101898, KB Topic: OPAL: Language Basics
-Collapse +Expand 16. ObjectPAL String Concatenation (+)
 

String literals s are limited to 255 characters but you can simply add two strings together as in:

s = "A long string." + "Another long string."
var
FirstName  String
  LastName  String
endVar
 
FirstName  = "Mike"
LastName  = "Prestwood"
msgInfo("", "Full name: " + FirstName + " " + LastName)
Posted By Mike Prestwood, Post #101593, KB Topic: OPAL: Language Basics
-Collapse +Expand 17. ObjectPAL Unary Operators
 

The ObjectPAL unary operators are:

+
-
Not

Posted By Mike Prestwood, Post #101897, KB Topic: OPAL: Language Basics
-Collapse +Expand 18. ObjectPAL Variables (var x SmallInt endVar)
 

Declaring variables is optional unless you click Program | Compiler Warnings while in the ObjectPAL editor for every form, script, and library you create. Using Compiler Warnings is strongly recommended to avoid incorrectly typing an existing variable and to avoid any confusion about variable scope. Also recommended is turning on Compile with Debug for every form, script, and library too for tighter, cleaner code.

Undeclared variables are AnyType variables. Common data types include Currency, Date, Datetime, Logical, LongInt, Number, SmallInt, String, and Time.

Declare local variables within a method. If you want a local static variable (retains it's value because it is not destroyed), declare the varialbes above the method. Variables declared in an object's Var window are visible to all methods attached to that object, and objects that it contains.

var
    FullName String
    Age SmallInt
    Weight Number
endVar
 
FullName = "Mike Prestwood"
Age = 32
Weight =154.4
msgInfo("", FullName + ", age=" + String(Age) 
             + ", weight=" + String(Weight))
Posted By Mike Prestwood, Post #101568, KB Topic: OPAL: Language Basics



Topic: OPAL: Language Details

-Collapse +Expand 19. Assocative Arrays in ObjectPAL
 

An associative array links a set of unique values (keys) to another set of values (not necessarily unique). In ObjectPAL associative arrays are known as dynamic arrays.

;Button :: pushButton
method pushButton(var eventInfo Event)
var
myDynArray   DynArray[] String
endVar

 
myDynArray["Last_Name"] = "Spitz"
myDynArray["First_Name"] = "Randy"
myDynArray.view()
endMethod
Posted By Mike Prestwood, Post #101198, KB Topic: OPAL: Language Details
-Collapse +Expand 20. ObjectPAL Associative Array (DynArray)
 

In ObjectPAL associative arrays are known as dynamic arrays.

var
myDynArray   DynArray[] String
endVar

 
myDynArray["Last_Name"] = "Spitz"
myDynArray["First_Name"] = "Randy"
myDynArray.view()
Posted By Mike Prestwood, Post #101518, KB Topic: OPAL: Language Details
-Collapse +Expand 21. ObjectPAL Exception Trapping (try...onFail)
 

ObjectPAL has a try...onFail statement but does not have a finally-type component. However, the code afer endTry will execute.

try
onFail
endTry
var
i SmallInt
endVar
try
i = 0
i = 1/i
onFail
msgInfo("", "You cannot divide by zero.")
endTry
Posted By Mike Prestwood, Post #101369, KB Topic: OPAL: Language Details
-Collapse +Expand 22. ObjectPAL Filter Records (setRanger, setGenFilter)
 

In ObjectPAL, you can filter set a TCursor, UIObject, and Table objects using setRange() and setGenFilter().

The following example loads, filters, and runs a report.

var
 r Report
 dyn DynArray[] String
endVar
  
dyn["Name"] = "SCUBA Heaven"
Customer.setGenFilter(dyn)
  
r.load(":Sample:customer")
r.Customer.setGenFilter(dyn)
r.run()

You can also drop a flter with:

r.Customer.dropGenFilter()
Posted By Mike Prestwood, Post #102115, KB Topic: OPAL: Language Details
-Collapse +Expand 23. ObjectPAL Find Record (locate, qLocate)
 

ObjectPAL provides a rich set of commands for finding a record with a TCursor or UIObject including:

  • locate() -  Seach for a value based on a criteria. Uses indexes as appropriate.
  • locatePattern() - Search for a pattern within a value.
  • moveToRecord() - Moves to a specific record number.
  • qLocate() - Search using currently set index.

Each of these basic find record commands has supporting commands such as locateNext() and recNo().

var
  tc TCursor
endVar
   
tc.open("Customer.db") 
if tc.locate("Name", "Proffessional Divers, Ltd.") then 
  tc.edit()
  tc.Name = "Professional Divers, Ltd."
  msgInfo("Success", "Corrected spelling error.")
endIf
tc.endEdit()
Posted By Mike Prestwood, Post #102113, KB Topic: OPAL: Language Details
-Collapse +Expand 24. ObjectPAL Overloading
 

Paradox & Overloading

  • Operator - No.
  • Method - No.

However, you can have the same named method or procedure so long as they are in different libraries. This is important if you use libraries in a class-like OOP way and wish to implement some form of polymorphism (i.e. libMember.Open and libVendor.Open). This is an OOP-like technique for implementing a subtyping-like polymorphism which is also known as inclusion polymorphism.

Also, some developers like to pass an array and then handle the array for a pseudo technique. Although not overloading, it's useful.

Posted By Mike Prestwood, Post #101464, KB Topic: OPAL: Language Details
-Collapse +Expand 25. ObjectPAL Parameters (var, const)
 

By Reference or Value (and by constant)
The default for parameters is by value. For by reference, add var in front of the parameter. ObjectPAL also offers constant parameters where you add const in front of the parameter. A constant parameter is like a read-only parameter the compiler can optimize. You cannot assign a value to a constant parameter.

method cmCode(s String) ;...s is by value.
endMethod
 
  
method pushButton(var eventInfo Event)
  ;...eventInfo is by reference.
endMethod
  
method cmCode(Const s String)
  ;...s is a constant read-only parameter.
endMethod
  
proc cpNever() String
  return "Never duplicate a line of code!"
endProc

Posted By Mike Prestwood, Post #101630, KB Topic: OPAL: Language Details
-Collapse +Expand 26. ObjectPAL Record Movement (home, end, nextRecord)
 

ObjectPAL uses home(), end(), nextRecord(), priorRecord() to move a database cursor (works with either a TCursor or UIObject).

TCursor.nextRecord()

These commands send a message to the object. Specifically, they send an action constant using the action command. The above snippet is equivalent to:

TCursor.action(DataNextRecord)

It is handy to  with familiar with action constants because not all action constants have an ObjectPAL equivalent comment.

The following snippet uses the active keyword to move to the second to last record of the table attached to the UIObject that currently has focus:

active.end()
active.priorRecord()

You can also use the self keyword to refer to the UIObject your code is attached to.

Posted By Mike Prestwood, Post #102109, KB Topic: OPAL: Language Details
-Collapse +Expand 27. ObjectPAL Self Keyword (Self)
 

A built-in object variable that represents the UIObject to which the currently executing code is attached.

method pushButton(var eventInfo Event)
  msgInfo("", self.Name)
endMethod
Posted By Mike Prestwood, Post #101934, KB Topic: OPAL: Language Details
-Collapse +Expand 28. ObjectPAL Sort Records (switchIndex, sortTo, setGenFilter)
 

In Paradox, you add an index for each sort your wish to perform on a table then use switchIndex(). Alternatively, you can use sortTo() to sort a table into a new table.

Posted By Mike Prestwood, Post #102118, KB Topic: OPAL: Language Details
-Collapse +Expand 29. ObjectPAL subStr
 

substr ( const startIndex LongInt [ , const numberOfChars LongInt ] ) String

Alternative syntax:

LeftString = subStr(NameVar, 1, 3)
var
�LeftString String;
  NameVar String;
endVar
NameVar = "Prestwood"
LeftString = NameVar.subStr(1, 3)
msgInfo("", LeftString)
Posted By Mike Prestwood, Post #101374, KB Topic: OPAL: Language Details
-Collapse +Expand 30. Paradox and OpenOffice
 

Export to OpenOffice

method openWorkBook(var Excel OleAuto, fileName string) logical
var
 StarDesktop,StarOffice  OLEAuto
 oooDoc,scr,lists,list,zak OleAuto
 massiv AnyType
 fs filesystem
 put,s string
 dlin,k,i smallInt
endVar
ShName.BLANK()
ShiNDEX.BLANK()
try
  scr.open("MSScriptControl.ScriptControl")
 scr.language = "javascript";
 scr.eval("aaa=new Array()")
 massiv = scr.eval("aaa")
 scr.AddCode("function SetItem(ind,val){massiv[ind]=val}")
 StarOffice.Open("com.sun.star.ServiceManager")
 StarDesktop=StarOffice.createInstance("com.sun.star.frame.Desktop")
 dlin=fileName.size()
 
 put=""
 k=1
 i=1
 while i<>dlin
  s=fileName.subStr(i,1)

  if ansiCode(s)=92 then 
   put=put+"/"+fileName.subStr(k,i-k)
   k=i+1
  endIf 

  i=i+1
 endWhile
 put=put+"/"+fileName.subStr(k,i-k+1)
 if put.subStr(put.size()-3,4)=".xls" then
 else
  put=put+".xls"
 endif
 Excel=StarDesktop.LoadComponentFromURL("file://"+put,"_blank", 0,massiv)
 return True
onFail errorClear() return False
endTry
endMethod
Posted By runlir, Post #101996, KB Topic: OPAL: Language Details



Topic: Interactive Paradox: Queries (QBE)

-Collapse +Expand 31. @ and ..
 
The first half is an inexact search and the second half tells it to limit the search to four characters.

QBE Expression...

 

mIkE.., @@@@
Posted By Mike Prestwood, Post #100814, KB Topic: Interactive Paradox: Queries (QBE)



Topic: Interactive Paradox: Reports

-Collapse +Expand 32. ObjectPAL Report Tools Overview (Built-In)
 

Paradox offers a built-in reporting tool that will suffice for most desktop database applications.

Posted By Mike Prestwood, Post #101649, KB Topic: Interactive Paradox: Reports



Topic: ObjectPAL Coding

-Collapse +Expand 33. ObjectPAL Overview and History
 

Language Overview: Object based language. Although ObjectPAL uses object oriented techniques "under the hood", it is not object oriented. Although you cannot create classes, ObjectPAL has built-in objects you can use in your code. You code in a traditional approach attaching code to objects or within a script. Most Paradox applications are form based. You may have a short startup script but you design forms and reports and tie them together with a common form. You can store reusable code such as custom methods and procedures in a library.

Target Platforms: Corel Paradox is most suitable for creating business desktop applications that run within Corel Paradox for Windows.

Posted By Mike Prestwood, Post #101722, KB Topic: ObjectPAL Coding



Topic: OPAL: Commands

-Collapse +Expand 34. ObjectPAL setTitle()
 

This code sets the title of your Paradox application in the application's title bar.

var
	app Application
endVar
app.setTitle("My Custom Application")
Posted By Mike Prestwood, Post #100587, KB Topic: OPAL: Commands



Topic: OPAL: Libraries

-Collapse +Expand 35. ObjectPAL Custom Routines (method, procedure)
 

ObjectPAL is a non-OOP language (an object-based language) that offers custom methods and custom procedures. When you create a custom method, you associate it with an existing object like a button, form, or library.

When calling a custom method or procedure that has a by reference parameter (uses var), then you cannot use a literal value. this is different than in many other languages which do allow you to pass literals by reference.

method sayHello(var pName String)
 msgInfo("", "Hello " + pName)
endMethod

method add(p1 Number, p2 Number) Number
 Return p1 + p2
endMethod
Posted By Mike Prestwood, Post #101631, KB Topic: OPAL: Libraries
-Collapse +Expand 36. ObjectPAL Pointers
 

ObjectPAL doesn't use pointers except for use with DLLs where you use a special CPTR uses keyword to refer to a DLL string pointer data type.

Uses Tapi32
  tapiRequestMakeCall(sNumber CPTR, sAppName CPTR, 
    sLogName CPTR, sComment CPTR) CLONG
endUses
Posted By Mike Prestwood, Post #101912, KB Topic: OPAL: Libraries



Topic: OPAL: OOP

-Collapse +Expand 37. ObjectPAL Inheritance (Not Supported)
 

ObjectPAL does not support developer defined class creation nor sub-classing (inheritance).

Posted By Mike Prestwood, Post #101395, KB Topic: OPAL: OOP
-Collapse +Expand 38. ObjectPAL Polymorphism (Not Supported)
 

Built-in: In ObjectPAL, polymorphism is the capability of the built-in objects to act differently depending on the context in which they are being used. For example, Table.Open and TCursor.Open. The Open method works differently depending on the object type used.

Custom: No. However,you can have the same named method or procedure so long as they are in different libraries.This is importantif you use librariesin a class-like OOP way and wish to implement some form of interfaces-like polymorphism(i.e. libMember.GetName and libVendor.GetName).

Posted By Mike Prestwood, Post #101470, KB Topic: OPAL: OOP



Topic: OPAL: Wicked Coding Tasks

-Collapse +Expand 39. Calling an Oracle Stored procedure from Paradox
 

In Paradox, use an sqlQuery block to call store procedures. The following code uses an sqlQuery block to call an Oracle stored procedure. Use the syntax of whatever SQL server you're going against. With Oracle, if I remember correctly, you use an "execProc" or "exec" command.

sqlQuery =
SQL
;execute proc here
ENDSQL


if not dbSQL.executeSQL(sqlQuery, tcAnswer) then
errorShow()
endIf
Posted By Mike Prestwood, Post #100072, KB Topic: OPAL: Wicked Coding Tasks
-Collapse +Expand 40. OLEAuto Paradox to Outlook
 

The following code snippet adds an appointment to your Outlook calendar. Tested with Paradox 9 and Outlook 2003 but should work with later versions of both programs.

Note, you will get a Error opening server 'Outlook.Application' error if your antivirus program is blocking Outlook access.

var
 oleOutlook oleAuto
 oleAppointment oleAuto
endVar
  
;The open will fail if your AntiVirus program is blocking access.
oleOutlook.open("Outlook.Application")
oleAppointment=oleOutlook.CreateItem(1)
  
oleAppointment.Subject = "Test From ObjectPAL"
oleAppointment.Body="You can add appointments from ObjectPAL."
oleAppointment.Start=dateTime() ;Adds an appointment now.
oleAppointment.Duration=60
oleAppointment.ReminderSet=True
oleAppointment.Location="My Office"
oleAppointment.BusyStatus = 2
  
oleAppointment.save()
Posted By Mike Prestwood, Post #102122, KB Topic: OPAL: Wicked Coding Tasks



Topic: Runtime, PDE, Package-It!

-Collapse +Expand 41. ObjectPAL Deployment Overview
 

To deploy a Paradox application, you need to deploy either the full version of Paradox or the Paradox Runtime both of which will include the BDE as well as any dependecies you've added such as psSendMail DLL, ezDialogs, etc.

Posted By Mike Prestwood, Post #101908, KB Topic: Runtime, PDE, Package-It!



Topic: P9 Book: Power Programming

Follow PrestwoodBoards on: 


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech