您的位置:首页 > 编程语言 > Delphi

BAPI / RFC with Delphi(系列之四)--TSAPFunctions使用(有登录对话框的delphi源代码)

2007-03-26 11:55 344 查看
1、新建一个Form,并在form上添加下列控件

Componentfunction
SAPFunctions1SAP ActiveX-component to connect RFC/BAPI
GridStringgrid to show the data's in the form
Button1Button to start the procedure
2、源代码如下(使用RFC_READ_TABLE函数读取成本中心)
unit logon1;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ExtCtrls, OleCtrls, StdCtrls, SAPFunctionsOCX_TLB, Grids;

type
TForm1 = class(TForm)
SAPFunctions1: TSAPFunctions;
Button1: TButton;
Grid: TStringGrid;
procedure Button1Click(Sender: TObject);
private
{ }
public
{ }
end;

var
Form1 : TForm1 ;
Table,Funct : VARIANT ;

implementation
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var txt : string ;
r : integer ;
begin

(* define function *)
Funct := SAPFunctions1.add('RFC_READ_TABLE');

(* tell the function what table should be read *)
Funct.exports('QUERY_TABLE').value := 'CSKT';

(* call the function *)
if not Funct.call then

(* on error show message *)
showMessage(Funct.exception)

else begin

(* select table with the data's *)
Table := Funct.tables.item('DATA');

(* addjust the StringGrid *)
grid.rowCount := Table.rowcount + 1;
grid.cells[0,0] := 'Client';
grid.cells[1,0] := 'Cost Number';
grid.cells[2,0] := 'CostCenter Description';
for r := 1 to grid.rowCount -1 do begin

(* select first dataset *)
txt := Table.value(r,1);

(* Because the RCF-function returns only one *)
(* string whitch contains all data's, the *)
(* string must be cut to different parts *)
grid.cells[0,r] := copy(txt,0,3); (* Client *)
grid.cells[1,r] := copy(txt,9,10); (* CostCent-number *)
grid.cells[2,r] := copy(txt,27,20); (* CostCent-description*)
end;
grid.visible := True;
end;
end;
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐