Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I translate this VB in DELPHI 1

Status
Not open for further replies.

LinuXelite

Programmer
Jun 21, 2002
150
CA
Hello!

I'm a consultant and I proposed Delphi to one of my customer.

We migrate his VB program in Delphi.

I have a problem though.. He has a database called "Commence RM" and I need to include this VB code into Delphi..

Can you help me to adapt this VB script:

function vb_function()
Set cmc = CreateObject("Commence.DB")
Set mes = cmc.getcursor(0, "Message", 0)

mes.SetSort "[ViewSort(""somefilter"", ascending)]", 0

If mes.rowcount() > 0 Then
Set qrs = mes.GetQueryRowSet(mes.rowcount(), 0)

colonne = qrs.GetColumnIndex("hour", 0)
hour = qrs.GetRowValue(mes.rowcount() - 1, colonne, 0)
end if

Set mes = Nothing
Set cmc = Nothing

End Function

Thank a lot!
 
It might be simpler just to tell us what you are trying to do. It looks like you are opening a data set and reading it thru just to get the last record (according to some sort specification).

I would guess that you could just use a TADOConnection and a TADOQuery to accomplish what you need. If you use

SELECT ...... ORDER BY xxxxxx DESC

then all you would need is to retrieve the first row from the result set.

What datbase engine are you using? (Access? SQL Server?)

What are the pertinent tables and columns that you are accessing?

 
Set cmc = CreateObject("Commence.DB")
Set mes = cmc.getcursor(0, "Message", 0)

mes.SetSort "[ViewSort(""somefilter"", ascending)]", 0


No I dont think this use ADO or any ODBC connection.

I think it uses some kind of COM object. I dont know.

Its similar to this code:

Set exceloo = CreateObject("excel.application")

and then you can use Excel in your program...

Francois,
 
The database engine is the Commence application.

There is not database or table, only category and fields (its the same, I know). Anyway this program suck :)
 
this might work
uses comobj;

function delphi_function()
var cmc, mes, qrs:OleVariant;
begin
cmc = CreateOleObject('Commence.DB');
mes = cmc.getcursor(0, 'Message', 0);

mes.SetSort ('[ViewSort,''somefilter'', ascending)]', 0);

If (mes.rowcount() > 0) Then
begin
qrs = mes.GetQueryRowSet(mes.rowcount(), 0);

colonne = qrs.GetColumnIndex('hour', 0);
hour = qrs.GetRowValue(mes.rowcount() - 1, colonne, 0);
end;
end;
this is as close as I can get to a line by line conversion (I didn't know what you were trying to return). I hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top