SAPGUI Scripting - Connection in Lazarus/FPC lazarus / 34-Windows ---------------------------------------------------------------------- kusana · 2016-05-12 20:02 Hello, I need to pilot SAPGUI from my own Lazarus app using the SAPGUI Scripting interface. I've found a similar help request on the SAP forum, but unfortunatly there is no answer: https://scn.sap.com/thread/2137793 Using VB.net I can connect to SAPGUI with a few lines of VB code: Imports SAPFEWSELib 'import SAPGUI Scripting library Public Class Form1     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click         Dim sapguiauto As Object = GetObject("SAPGUI") 'create activex object         Dim application As GuiApplication = sapguiauto.getscriptingengine 'get scripting engine         Dim connection As GuiConnection = application.Children(0) 'get first connection         Dim session As GuiSession = connection.Children(0) ' get first session         session.FindById("wnd[0]/tbar[0]/okcd").text = "IW23" 'select transaction IW23         session.FindById("wnd[0]").sendvkey(0) 'send return key         session.FindById("wnd[0]/usr/ctxtRIWO00-QMNUM").text = "91013157" 'feed additional data         session.FindById("wnd[0]").sendvkey(0) 'send return key     End Sub End Class It would be nice if someone could convert these few lines of VB code to FPC/Lazarus code. I've already imported SAPFEWSELib from "c:\program files\sap\frontend\sapgui\sapfewse.ocx", but I'm not able to create the ActiveX object properly. Within "sapfewselib_1_0_tlb.pas" converted file I find:   TEvsGuiSession = Class(TEventSink)   and    TEvsGuiApplication = Class(TEventSink) Thank you in advance for your help. ---------------------------------------------------------------------- kusana · 2016-05-27 08:58 Finally I managed to write the following piece of Lazarus/FPC code to control an active session: uses   ..., saprotwr_1_0_tlb, sapfewselib_1_0_tlb; var   MySapROTWrapper: ISapROTWrapper;   MySapROTEntry: _Dsapfewse;   MyGuiApplication: GuiApplication;   MyGuiConnection: GuiConnection;   MyGuiSession: GuiSession;   MyGuiFrameWindow: GuiFrameWindow; begin   MySapROTWrapper := CoCSapROTWrapper.Create;   MySapROTEntry := _Dsapfewse(MySapROTWrapper.GetROTEntry('SAPGUI'));   MyGuiApplication := GuiApplication(MySapROTEntry.GetScriptingEngine);   MyGuiConnection := GuiConnection(MyGuiApplication.Children.Item(0));   MyGuiSession := GuiSession(MyGuiConnection.Children.Item(0));   MyGuiFrameWindow := GuiFrameWindow(MyGuiSession.Children.Item(0));   GuiTextField(MyGuiFrameWindow.findById('wnd[0]/tbar[0]/okcd', GuiTextField_)).Text_ := 'my transaction here';   MyGuiFrameWindow.SendVKey(0);   GuiTextField(MyGuiFrameWindow.findById('wnd[0]/usr/text field id here', GuiTextField_)).Text_ := 'text data';   MyGuiFrameWindow.SendVKey(0); ... and so on. ---------------------------------------------------------------------- jma_sp · 2016-12-29 09:57 Thank Kusana, i don´t know how to use it but it is very interesting thing interact with SAP. Works with an active session directly? Can it be used to extract obtained data of SAP? Can you write a little practical tutorial with simple steps?