on 2025 Mar 07 6:00 PM
I am developing an application in Delphi that needs to interact with SAP GUI via Scripting to automate some material control operations. However, I am facing difficulties in establishing the correct communication with SAP GUI Scripting and executing the desired commands.
Scenario:
Issues faced:
Error when trying to access the session object: some attempts return errors like Object required or ActiveX component can't create object
Code works in VBA but not in Delphi: I tested some scripts in VBA (Excel) and in a VBS file, and they work fine. However, when porting to Delphi, I cannot reproduce the same behavior.
Example of code used:
uses
ComObj, Variants;
procedure TForm1.Button1Click(Sender: TObject);
var
SAPGuiAuto, Application, Connection, Session: OleVariant;
begin
try
SAPGuiAuto := GetActiveOleObject('SAPGUI.ScriptingCtrl.1');
//SAPGuiAuto := CreateOleObject('SAPGUI.ScriptingCtrl.1');
Application := SAPGuiAuto.GetScriptingEngine;
Connection := Application.Children(0);
Session := Connection.Children(0);
// Test: Access a transaction
Session.StartTransaction('MMBE');
except
on E: Exception do
ShowMessage('Err: ' + E.Message);
end;
end;
Questions:
Request clarification before answering.
User | Count |
---|---|
7 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.