SAP SCRIPT

    技术2022-05-13  25

    library newDll;

    { Important note about DLL memory management: ShareMem must be the  first unit in your library's USES clause AND your project's (select  Project-View Source) USES clause if your DLL exports any procedures or  functions that pass strings as parameters or function results. This  applies to all strings passed to and from your DLL--even those that  are nested in records and classes. ShareMem is the interface unit to  the BORLNDMM.DLL shared memory manager, which must be deployed along  with your DLL. To avoid using BORLNDMM.DLL, pass string information  using PChar or ShortString parameters. }

    uses    SysUtils,    Classes,    SAPFEWSELib_TLB,    ActiveX,    Forms,    forevent in 'forevent.pas' {myf};

    {$R *.res}//所有 string 被修改成 pchar ,为了 c# 调用不出错

    function connSap(sys: PChar; uname: PChar; pw: PChar): Integer; stdcall;var    conn: GuiConnection;

        win: GuiMainWindow;    r: Variant;

    begin    try        //连接        coinitialize(nil);

            if myf = nil then            myf := tmyf.Create(nil);

            if myf.gplctn1 = nil then            myf.gplctn1 := TGuiApplication.Create(myf);

            //if myf = nil then          //  myf := Tmyf.Create(nil);

           // gplctn1.OnDestroySession := myf.OnDestroySession;

            if myf.gplctn1.Children.Count <= 0 then            conn := myf.gplctn1.OpenConnection(sys);

            //ShowMessage(IntToStr(Self.gplctn1.Connections.Count));

            if myf.gplctn1.Connections.Count <= 0 then        begin            //ShowMessage('0000000');            Result := 0;            Exit;        end;

            conn := GuiConnection(myf.gplctn1.Connections.Item(0));

            //                        ShowMessage(   IntToStr(     conn.Children.Count  ));        //sess := GuiSession(conn.Children.Item(0));        sess := GuiSession(conn.Sessions.ElementAt(0));

            win := GuiMainWindow(sess.FindById('wnd[0]', r));        win.Maximize;

            GuiTextField(sess.FindById('wnd[0]/usr/txtRSYST-BNAME', r)).Text :=            uname;        GuiPasswordField(sess.FindById('wnd[0]/usr/pwdRSYST-BCODE', r)).Text :=            pw;

            win.SendVKey(0);        sleep(300);

            result := 1;

            //iscall := 0;        if myf.gplctn1.Connections.Count > 0 then        begin            //iscall := 100;            result := 1;        end;    except        result := -1;    end;end;

    function clearRes: Integer; stdcall;begin

        if myf.gplctn1 <> nil then    begin        sess := nil;

            myf.gplctn1.Quit;        Sleep(200);        myf.gplctn1.Free;

            myf.gplctn1 := nil;    end;    CoUninitialize;

        if myf <> nil then    begin        //myf.Destroy;        myf.Free;        myf := nil;    end;

        //iscall := 0;

        Result := 1;end;

    function uploadPhoto(sys: PChar; uname: PChar; pw: PChar; ipernr: Integer;    P_PATH: PChar):    Integer; stdcall;var    r: Variant;    win: GuiMainWindow;    pernr: string;begin    //照片上传   先自动判断连接    //判断是否已经断掉    //if myf.gplctn1 = nil then     // iscall := 0;    if myf = nil then        connSap(sys, uname, pw);

        try        if myf.gplctn1.Connections.Count <= 0 then            connSap(sys, uname, pw);

            if myf.gplctn1.Connections.Count <= 0 then        begin            Result := -1; //没有连接            Exit;        end;

            pernr := IntToStr(ipernr);        GuiTextField(sess.findById('wnd[0]/tbar[0]/okcd', r)).text :=            '/nzhrphoto';        win := GuiMainWindow(sess.FindById('wnd[0]', r));        win.SendVKey(0);

            Sleep(200);

            GuiTextField(sess.findById('wnd[0]/usr/ctxtP_PERNR', r)).text := pernr;        GuiTextField(sess.findById('wnd[0]/usr/ctxtP_PERNR', r)).CaretPosition            := 0;

            GuiTextField(sess.findById('wnd[0]/usr/txtP_PATH', r)).text := P_PATH;        ///!!!!!!!!        GuiTextField(sess.findById('wnd[0]/usr/txtP_PATH', r)).CaretPosition;

            Guibutton(sess.findById('wnd[0]/tbar[1]/btn[8]', r)).Press;

            Sleep(200);

            pernr := GuiStatusbar(sess.findById('wnd[0]/sbar', r)).Text;        if pernr = 'OK' then            Result := 1        else            Result := 0;

        except        Result := -1;    end;end;

    exports    connSap, clearRes, uploadPhoto;beginend.

     


    最新回复(0)