系統程式
# FastERP 系統程式
該手冊內的內容用於編寫指令碼時作為參考,包含系統中使用的部分程式。
# 1. 字串處理程式
# 1.1. Delete
procedure Delete(var S: string; Index,Count: Integer);
1
- 該過程從一個字串中移除一個子串。
| 部分 | 說明 |
|---|---|
| S | 字串表達式 |
| Index | 整形表達式,表示刪除字串的起始位置 |
| Count | 整形表達式,表示刪除的字元數 |
- 示例:
var
s1: String;
begin
s1 := 'Hi,Hello';
Delete(s1,1,4);
ShowMessage(s1);
end;
1
2
3
4
5
6
7
2
3
4
5
6
7
- 運行結果:
ello
# 1.2. Insert
procedure Insert(Source: String; var S: String; Index:Integer);
1
- 該過程以某個位置開始相字串中插入一個子字串。
| 部分 | 說明 |
|---|---|
| Source | 字串表達式 |
| S | 字串表達式,作為插入的數據 |
| Index | 整形表達式,表示插入字串的起始位置 |
- 示例:
var
s1: String;
s2: String;
begin
s1 := 'Hi,Hello';
s2 := 'IsoFace,';
Insert(s2,s1,0);
ShowMessage(s1);
end;
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
- 運行結果:
IsoFace,Hi,Hello
# 1.3. SetLength
procedure SetLength(var S; NewLength: Integer);
1
- 該過程用於設定字串或動態陣列的長度。
| 部分 | 說明 |
|---|---|
| S | 字串或者動態陣列表達式 |
| NewLength | 整形表達式,用於設定字串或動態陣列的長度 |
- 示例
var
arr: Array of Integer;
i: Integer;
begin
SetLength(arr,5);
for i := 0 to 4 do
begin
arr[i] := i;
ShowMessage(IntToStr(arr[i]));
end;
end;
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
- 運行結果
0 1 2 3 4
# 1.4. StrToStream
Procedure StrToStream(AString:String;AStream:TMemoryStream);
1
- 該程式將字串轉換為流。
| 部分 | 說明 |
|---|---|
| AString | 要被轉換的字串 |
| AStream | 轉換后的流 |
# 1.5. Val
procedure Val(S; var V; var Code: Integer);
1
- 該函式轉換一個數字格式字串為數字表達式。
| 部分 | 說明 |
|---|---|
| S | 是一個字串表達式,它必須是由一系列數字格式的字元組成 |
| V | 是一個整形或實形表達式,如果V是一個整數,則S必須能夠轉換為整數 |
| Code | 是一個整形表達式,如果字串S不符合要求,則該非數字字元索引會被儲存在Code中,否則Code會被設定為0,對於以Null結尾的字元,非數字字元返回的錯誤位置比實際的以0基準的字元索引大1 |
- 示例:
var
s1: String; i,m: Integer;
begin
s1 := '3231EC5';
Val(s1,i,m);
if m = 0 then
ShowMessage(IntToStr(i))
else
ShowMessage(IntToStr(m));
end;
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
- 運行結果:
5
# 2. 科學計算程式
# 2.1. DivMod
procedure DivMod(Dividend: Cardinal; Divisor: Word; var Result, Remainder: Word);
1
- 該過程返回兩個運算元相除的商和餘數。
| 部分 | 說明 |
|---|---|
| Dividend | 整型表達式,表示被除數 |
| Divisor | 整型表達式,表示除數 |
| Result | 整型表達式,用於儲存Dividend與Divisor相除的商 |
| Remainder | 整型表達式,用於儲存餘數 |
- 示例:
var
a,b: word;
begin
DivMod(13,3,a,b);
ShowMessage(IntToStr(a) + ' ' + IntToStr(b));
DivMod(15,3,a,b);
ShowMessage(IntToStr(a) + ' ' + IntToStr(b));
end;
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
- 運行結果:
4 1 5 0
# 3. 序數程式
# 3.1. Inc
procedure Inc(var X[;N:Longint]);
1
- 該過程用於整數自加N。
| 部分 | 說明 |
|---|---|
| X | 待增加的整數 |
| N | 增加的步長,無步長時,預設加1 |
- 示例:
var
i: Integer;
j: Integer;
k: Integer;
begin
i := 1; j:= 1; k:= 1;
Inc(i);
Inc(j,4);
Inc(k,8);
ShowMessage(IntToStr(i));
ShowMessage(IntToStr(j));
ShowMessage(IntToStr(k));
end;
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
- 運行結果:
2 5 9
# 3.2. MomentSkewKurtosis
procedure MomentSkewKurtosis(const Data: array of Double; var M1, M2, M3, M4, Skew, Kurtosis: Extended);
1
- 計算一組數據的各項統計指標
| 部分 | 說明 |
|---|---|
| Data | 一個浮點型陣列 |
| M1 | 平均數 |
| M2 | 差值 |
| M3 | 傾斜度 |
| M4 | 峰度 |
| Skew | 傾斜度係數 |
| Kurtosis | 峰度係數 |
- 示例:
var
M1,M2,M3,M4,Skew,Kurtosis: Extended;
begin
MomentSkewKurtosis([1.21,2.02,3.3,4.2,5.6,6.5,7.1],M1,M2,M3,M4,Skew,Kurtosis);
ShowMessage(FloatToStr(M1));
ShowMessage(FloatToStr(M2));
ShowMessage(FloatToStr(M3));
ShowMessage(FloatToStr(M4));
ShowMessage(FloatToStr(Skew));
ShowMessage(FloatToStr(Kurtosis));
end;
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
- 運行結果:
4.27571428571429 4.30319591836735 -0.766464402332362 29.4727402330112 -0.0858628520935413 1.59161593158165
# 4. 金融程式
該章節暫無可用程式。
# 5. 隨機數程式
# 5.1. Randomize
procedure Randomize;
1
該程式用於初始化內建的隨機數產生器。
示例:
begin
Randomize;
ShowMessage(IntToStr(Random(10)));
end;
1
2
3
4
2
3
4
- 運行結果:運行該語句后產生一個大於等於0小於10的整數。
# 6. 單位轉換程式
# 6.1. RaiseConversionError
procedure RaiseConversionError(const AText: string);
1
- 該程式用於觸發一個單位轉換異常。
| 部分 | 說明 |
|---|---|
| AText | 字串表達式,用於指定異常產生時的訊息 |
| AArgs | 陣列常量表達式,用於支援AText所標識的格式 |
- 示例:
begin
RaiseConversionError('型別轉換錯誤');
end;
1
2
3
2
3
- 運行結果:彈出錯誤提示。
# 7. 日期程式
# 7.1. DecodeDate
procedure DecodeDate(Date: TDateTime; var Year,Month,Day:Word);
1
- 該程式分解TDateTime型別表達式為年、月、日。
| 部分 | 說明 |
|---|---|
| Date | 待分解的TDateTime值 |
| Year | 得到TDateTime值分解后的年份 |
| Month | 得到TDateTime值分解后的月份 |
| Day | 得到TDateTime值分解后的日 |
- 示例:
var
Year,Month,Day: Word;
begin
DecodeDate(Now,Year,Month,Day);
ShowMessage(IntToStr(Year) + '年' + IntToStr(Month) + '月' + IntToStr(Day) + '日');
end;
1
2
3
4
5
6
2
3
4
5
6
- 運行結果:顯示目前日期的年月日資訊。
# 7.2. DecodeDateDay
procedure DecodeDateDay(const AValue: TDateTime; out AYear, ADayOfYear: Word);
1
- 該程式把TDateTime型別表達式分解為年和該日是該年的第幾天。
| 部分 | 說明 |
|---|---|
| AValue | 待分解的TDateTime值 |
| AYear | 返回日期表達式的年份 |
| ADayOfYear | 返回日期表達式表示的日是該年的第幾天 |
- 示例:
var
Year,Month,Day: Word;
begin
DecodeDateDay(StrToDate('2020-11-1'),Year,Day);
ShowMessage(IntToStr(Year) + '年第' + IntToStr(Day) + '日');
end;
1
2
3
4
5
6
2
3
4
5
6
- 運行結果:
2020年第306日
# 7.3. DecodeDateMonthWeek
procedure DecodeDateMonthWeek(const AValue: TDateTime; out AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word);
1
- 該程式獲得TDateTime型別表達式指定的日期表示燈年份,月份以及該月的第幾周和周值。
| 部分 | 說明 |
|---|---|
| AValue | 待分解的日期時間表達式 |
| AYear | 返回日期表達式的年份 |
| AMonth | 返回日期表達式的月份 |
| AWeekOfMonth | 返回該日是當月的第幾周 |
| ADayOfWeek | 返回當日的周值 |
- 示例:
var
Year,Month,weekofmonth,dayofweek: word;
begin
DecodeDateMonthWeek(StrToDate('2020-11-1'),Year,Month,weekofmonth,dayofweek);
ShowMessage(IntToStr(Year) + ' ' + IntToStr(Month) + ' ' + IntToStr(weekofmonth) + ' ' + IntToStr(dayofweek));
end;
1
2
3
4
5
6
2
3
4
5
6
- 運行結果:
2020 10 5 7
# 7.4. DecodeDateTime
procedure DecodeDateTime(const AValue: TDateTime; out AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word);
1
- 該函式把TDateTime的值拆分成年、月、日、小時、分、秒、毫秒。
| 部分 | 說明 |
|---|---|
| AValue | 待分解的日期時間表達式 |
| AYear | 返回日期表達式的年份 |
| AMonth | 返回日期表達式的月份 |
| ADay | 返回日期表達式表示的日 |
| AHour | 返回日期表達式表示的小時 |
| AMinute | 返回日期表達式表示的分鐘 |
| ASecond | 返回日期表達式表示的秒鐘 |
| AMillisecond | 返回日期表達式表示的毫秒 |
- 示例:
var
Year,Month,Day,Hour,Minute,Second,MilliSecond: word;
begin
DecodeDateTime(StrToDateTime('2020-11-1 13:25:43.323'),Year,Month,Day,Hour,Minute,Second,MilliSecond);
ShowMessage(IntToStr(Year) + ' ' + IntToStr(Month) + ' ' + IntToStr(Day) + ' ' + IntToStr(Hour)
+ ' ' + IntToStr(Minute) + ' ' + IntToStr(Second) + ' ' + IntToStr(MilliSecond));
end;
1
2
3
4
5
6
7
2
3
4
5
6
7
- 運行結果:
2020 11 1 13 25 43 323
# 7.5. DecodeDateWeek
procedure DecodeDateWeek(const AValue: TDateTime; out AYear, AWeekOfYear, ADayOfWeek: Word);
1
- 該程式將指定的日期表示為第幾周和星期幾,以及所在的年份。
| 部分 | 說明 |
|---|---|
| AValue | 待分解的日期時間表達式 |
| AYear | 返回日期表達式的年份 |
| AWeekOfYear | 返回日期表達式該日期是當年的第多少周 |
| ADayOfWeek | 返回日期表達式的星期 |
- 示例:
var
Year,WeekOfYear, DayOfWeek: word;
begin
DecodeDateWeek(StrToDate('2020-11-1'),Year,WeekOfYear,DayOfWeek);
ShowMessage(IntToStr(Year) + ' ' + IntToStr(WeekOfYear) + ' ' + IntToStr(DayOfWeek));
end;
1
2
3
4
5
6
2
3
4
5
6
- 運行結果:
2020 44 7
# 7.6. DecodeDayOfWeekInMonth
procedure DecodeDayOfWeekInMonth(const AValue: TDateTime; out AYear, AMonth, ANthDayOfWeek, ADayOfWeek: Word);
1
- 該程式用於將TDateTime型別的表達式指定的日期拆分成年、月、日、周值,以及周值在本月的序號。
| 部分 | 說明 |
|---|---|
| AValue | 待分解的日期時間表達式 |
| AYear | 返回日期表達式的年份 |
| AMonth | 返回日期表達式的月份 |
| ANthDayOfWeek | 返回日期表達式的星期值在本月的序號 |
| ADayOfWeek | 返回日期表達式的星期 |
- 示例:
var
Year,Month,NthDayOfWeek,DayOfWeek: word;
begin
DecodeDayOfWeekInMonth(StrToDate('2020-11-1'),Year,Month,NthDayOfWeek,DayOfWeek);
ShowMessage(IntToStr(Year) + ' ' + IntToStr(Month) + ' ' + IntToStr(NthDayOfWeek) + ' ' +IntToStr(DayOfWeek));
end;
1
2
3
4
5
6
2
3
4
5
6
- 運行結果:
2020 11 1 7
# 7.7. DecodeTime
procedure DecodeTime(Time: TDateTime; var Hour,Min,Sec,MSec:Word);
1
- 該過程將TDateTime表達式的日期時間拆分成時、分、秒、毫秒。
| 部分 | 說明 |
|---|---|
| Time | 待分解的時間表達式 |
| Hour | 返回時間表達式的小時 |
| Min | 返回時間表達式的分鐘 |
| Sec | 返回時間表達式的秒鐘 |
| MSec | 返回時間表達式的毫秒 |
- 示例:
var
hour,minute,second,millisecond: Word;
begin
DecodeTime(Now,hour,minute,second,millisecond);
ShowMessage(IntToStr(hour) + ':' + IntToStr(minute) + ':' + IntToStr(second) + ':'
+ IntToStr(millisecond));
End;
1
2
3
4
5
6
7
2
3
4
5
6
7
該語句執行后,顯示目前的系統時間。
# 7.8. IncAMonth
procedure IncAMonth(var Year, Month, Day: Word; NumberOfMonths: Integer = 1);
1
- 根據指定的值來增加或修改月份。
| 部分 | 說明 |
|---|---|
| Year | 返回年份 |
| Month | 返回月份 |
| Day | 返回日 |
| NumberOfMonths | 待增加或減少月的數量 |
- 示例:
Var
Year,Month,Day: Word;
begin
Year := 2020;
Month := 11;
Day := 1;
IncAMonth(Year,Month,Day,1);
ShowMessage('下個月的日期為:' + IntToStr(Year) + '年' + IntToStr(Month) + '月' + IntToStr(Day) + '日');
end;
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
- 運行結果:
下個月的日期為2020年12月1日
# 7.9. ReplaceDate
procedure ReplaceDate(var DateTime: TDateTime; const NewDate: TDateTime);
1
- 該過程將指定時間中的日期替換為其他日期。
| 部分 | 說明 |
|---|---|
| DateTime | 將要替換日期部分的時間 |
| NewDate | 替換日期的指定值 |
返回值:返回替換后的日期。
示例:
var
ADate: TDateTime;
BDate: TDateTime;
begin
ADate := StrToDate('2020-11-01');
BDate := StrToDate('2020-10-01');
ReplaceDate(ADate,BDate);
ShowMessage(DateToStr(ADate));
end;
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
- 運行結果:
2020-10-01、
# 7.10. ReplaceTime
procedure ReplaceDate(var DateTime: TDateTime; const NewDate: TDateTime);
1
- 該過程將指定時間中的時間替換為其他時間。
| 部分 | 說明 |
|---|---|
| DateTime | 將要替換的時間 |
| NewDate | 指定替換的時間 |
返回值:返回替換后的時間。
示例:
var
ADate: TDateTime;
BDate: TDateTime;
begin
ADate := StrToDateTime('2020-11-01 12:00:00');
BDate := StrToDateTime('19:28:17');
ReplaceTime(ADate,BDate);
ShowMessage(DateTimeToStr(ADate));
end;
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
- 運行結果:
2020-11-01 19:28:17
# 8. 檔案處理程式
# 8.1. ChDir
procedure ChDir(const S: string);
1
- 該程式將目前目錄修改爲指定目錄。
| 部分 | 說明 |
|---|---|
| S | 指定修改的目錄 |
- 示例:
begin
ChDir('..\');
end;
1
2
3
2
3
- 運行結果:將目前目錄修改爲指定的目錄。
# 8.2. RmDir
procedure RmDir(const S: string);
1
- 該程式刪除一個空的資料夾。
| 部分 | 說明 |
|---|---|
| S,P | 將要刪除的資料夾名稱 |
- 示例:
begin
RmDir('Sample');
end;
1
2
3
2
3
- 運行結果:上述語句將
Sample資料夾刪除。
# WriteIni
procedure WriteIni(filename,section,Ident,Values:String);
1
- 該程式用於設定向ini配置檔案寫入配置資訊。
| 部分 | 說明 |
|---|---|
| filename | 檔名稱 |
| section | 配置分組名稱 |
| Ident | 配置參數值名稱 |
| Values | 配置參數取值 |
# 9. 格式化程式
# 9.1. FmtStr
procedure FmtStr(var Result: string; const Format: string; const Args: array of const);
1
- 該程式按指定方式格式化一個陣列常量的字元形式。使用方法與Format相同,不同的是把返回值放在了Result參數中。
| 部分 | 說明 |
|---|---|
| Result | 是一個字串表達式,將格式化后的字串儲存在該變數中 |
| Format | 是一個字串表達式,指定格式化所使用的格式 |
| Args | 是一個陣列表達式,指定要格式化的內容 |
| FormatSettings | 是一個記錄型別,包含了系統預定義的格式化方法 |
- 示例:
var
Str: String;
begin
FmtStr(Str,'x=%.5d',[2]);
ShowMessage(Str);
end;
1
2
3
4
5
6
2
3
4
5
6
- 運行結果:
x=00002
# 9.2. WideFmtStr
procedure WideFmtStr(var Result: WideString; const Format: WideString; const Args: array of const);
1
- 該程式按指定方法格式化一個陣列常量的多位元組字元形式。
| 部分 | 說明 |
|---|---|
| Result | 用於存放格式化后的字串 |
| Format | 指定格式化所使用的格式 |
| Args | 是一個陣列表達式,指定要格式化的內容 |
| FormatSettings | 是一個記錄型別,包含了系統預定義的格式化方法 |
- 示例:
var
S: WideString;
begin
WideFmtStr(S,'%1:s %0:s',['How Are You!','Hello!']);
ShowMessage(S);
end;
1
2
3
4
5
6
2
3
4
5
6
- 運行結果:
Hello! How Are You!
# 10. 對話方塊程式
# 10.1. ShowMessage
procedure ShowMessage(const Msg: String);
1
- 該過程顯示一個簡單的訊息框。
| 部分 | 說明 |
|---|---|
| Msg | 訊息對話方塊要顯示的提示資訊內容 |
begin
ShowMessage('Hello');
end;
1
2
3
2
3
執行上述程式碼,彈出Hello提示。
# 11. 流程控制
# 11.1. Abort
procedure Abort;
1
- 該過程產生一個特殊的"無記載異常",此異常與其他異常相同,只是不顯示錯誤資訊。
# 11.2. Exit
proceure Exit;
1
- 該過程立即使控制退出目前過程,繼續執行此過程呼叫位置后的程式碼,如果目前過程為主程式,則程式終止運行。