控制元件使用
# 控制元件使用
以下是在工作流的指令碼中可以使用的控制元件,以及使用方法的說明。
# 1. RestAPI
FastBPM中的RestAPI控制元件作為客戶端使用,可向其它服務發送請求。使用的示例如下:
//回撥事件,接收返回的資訊
procedure OnRestAPIResultData(Sender:TObject;AResult:String);
begin
ShowMessage(AResult);
end;
//主程式
var
rest: TRestAPI;
begin
rest := TRestAPI.Create(nil);
try
//繫結事件
rest.OnResultData := 'OnRestAPIResultData';
//屬性賦值
//API的描述資訊
rest.Caption := 'GUID';
//設定RestAPI伺服器,格式如下,埠號後面不要加 '/'
rest.Server := 'https://web.diylogi.com';
//如果基礎地址後有其它的相對地址,可加至此。
rest.Url := '';
//期望返回的內容型別
rest.ContentType := 'text/html';
//請求方法 rmPOST、rmGET、rmPUT、rmDELETE
rest.Method := rmGET;
//URL參數定義,如有多個參數則分成多行,如下所示。
rest.Params.Add('restapi=script');
rest.Params.Add('apiname=guid');
//呼叫
rest.Send;
finally
//釋放
rest.Free;
end;
end.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 2. 遠端列印
遠端列印功能由Flying提供,FastBPM中提供了客戶端控制元件TFlying
,方便使用者在自定程式中使用。
在使用前,請先參考Flying 報表設計說明設計定義數據源格式,以及需要使用的報表格式。
FastBPM中使用的示例如下:
//配合FastERP2中的遠端列印自定按鈕實現遠端列印的功能
var
F: TFlying;
DA: TRFDataSet;
DB: TRFDataSet;
begin
//建立TFlying控制元件
F := TFlying.Create(nil);
DA := TRFDataSet.Create(nil);
DB := TRFDataSet.Create(nil);
try
DA.Connection := UGDM.DBConnection;
DB.Connection := UGDM.DBConnection;
DA.ConnectionDefName := 'fasterp2';
DB.ConnectionDefName := 'fasterp2';
//此處的SQL查詢,查詢的結果中包含的欄位與報表設計環節定義的數據源的欄位一致
DA.SQL.Text := 'select * from SdShipOrder where shipno = ''IVL20240129001''';
DB.SQL.Text := 'select * from SdShipPart where shipno = ''IVL20240129001''';
//從自定程式的URL參數中獲取參數值,並賦值
DA.OpenData;
DB.OpenData;
if (DA.RecordCount > 0) and (DB.RecordCount > 0) then
begin
F.PrintOptions.PrintType := HTTP;
F.PrintOptions.ReportName := 'fasterp2_shiporder.fr3';
F.HTTPOptions.Host := '127.0.0.1';
F.HTTPOptions.Port := 8801;
F.PrintOptions.Data.Add('"AData":'+DA.ToJsonArrayString);
F.PrintOptions.Data.Add('"BData":'+DB.ToJsonArrayString);
F.Print;
end;
finally
//執行完成,釋放記憶體
DA.Free;
DB.Free;
F.Free;
end;
end.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38