?? upublic.pas
字號:
unit uPublic;
interface
uses
Windows, Messages,
SysUtils, Classes;
type
TFileRec = record
FuncName,
AppName: string[128];
Charline: string[10];
Data: array[1..8,1..10] of String[3];
end;
TFileRecError = class(Exception);
//這些沒有用到:
//begin
C1 = '!'..'/';
C2 = ':'..'@';
C3 = '['..'`';
C4 = '{'..'~';
lk = 'a'..'z';
uk = 'A'..'Z';
Num = '0'..'9';
//end;
TCharType = (ctNum,ctDot,ctABC,ctEmpty);
function SaveToFile(const FileName: string; const dt: TFileRec; Add: Boolean = true): Boolean;
Function LoadFormFile(const FileName: string; var dt: TFileRec): Boolean;
Function CheckData(dt: TFileRec; var ErrStr: string): Boolean;
Function GetKeyByFunc(Code: string; Dt: TFileRec): string;
function GetFirstKeyWord(var pos: Integer;var Typ: TCharType; code: string):string;
Function GetKeyType(pos: integer; Code: string):TCharType;
function GetIndexByChar(const dt: TFileRec; const c: Char):integer;
Function GetKeyWord(dt: TFileRec; const c: Char; i: Integer ): string;
implementation
var
j: integer;
begin
result := '';
j := GetIndexByChar(dt,c);
if j <> -1 then
begin
if (i >= low(dt.Data)) and (i <= high(dt.Data)) then
result := dt.Data[i,j];
end;
end;
Function CheckData(dt: TFileRec; var ErrStr: string): Boolean;
Function CheckKey(const s: string): boolean;
var
i: integer;
begin
result := true;
for i := 1 to 3 do
if not (s[i] in ['0'..'9']) then
result := false;
end;
var
i,j: integer;
s: string[3];
begin
result := Boolean(1);
if Trim(dt.FuncName) = '' then
begin
result := false;
ErrStr := '函數(shù)名稱出現(xiàn)問題.';
exit;
end;
dt.Charline := LowerCase(dt.Charline);
for i := 1 to 10 do
if not (dt.Charline[i] in ['a'..'z']) then
begin
result := false;
ErrStr := '序列字母出現(xiàn)問題.';
Break;
end;
if integer(result) > 0 then
begin
for i := Low(dt.data) to High(dt.data) do
if Result then
for j := Low(dt.data[i]) to high(dt.data[i]) do
begin
s := dt.data[i,j];
if not CheckKey(s) then
begin
ErrStr := '解碼字符出現(xiàn)問題.';
result := false;
Break;
end;
end;
end;
end;
Function GetKeyByFunc(Code: string; Dt: TFileRec): string;
var
len,pos: Integer;
typ: TCharType;
s: string;
Turbo: boolean;
begin
code := LowerCase(Code);
pos := 1;
len := length(code);
Dt.Charline := LowerCase(dt.Charline);
dt.FuncName := trim(LowerCase(dt.FuncName));
Turbo := true;
s := GetFirstKeyword(pos,typ,Code);
case typ of
ctNum,
ctDot:
begin
result := '聲明函數(shù)名稱的字符是錯誤的.';
exit;
end;
ctEmpty:
begin
result := '空白的代碼.';
exit;
end;
ctAbc: Turbo := SameText(s,Dt.FuncName);
end;
if not turbo then
begin
result := '沒有找到匹配的函數(shù)名稱.';
Exit;
end;
s := GetFirstKeyword(pos,typ,Code);
case typ of
ctNum,
ctABC:
begin
result := '發(fā)現(xiàn)多余的文本:' + s;
exit;
end;
ctEmpty: result := '代碼異常結(jié)束了.';
ctDot: TurBo := s = '(';
end;
if not Turbo then
begin
result := '函數(shù)之后緊跟著的符號是:"(". ';
exit;
end;
s := GetFirstKeyword(pos,typ,Code);
if typ = ctAbc then
begin
while Length(s) < 4 do
begin
s := s + GetFirstKeyword(pos,typ,code);
if (typ = ctdot) or (typ = CtEmpty) then
begin
result := '參數(shù)錯誤.';
Turbo := false;
Break;
end;
end;
end
else
result := '參數(shù)錯誤.';
if Turbo then
begin
if length(s) > 4 then
begin
result := '參數(shù)錯誤.';
end
else
if not ((s[1] in ['a'..'z']) and (s[2] in ['0'..'9'])
and (s[1] in ['a'..'z']) and (s[2] in ['0'..'9']) ) then
result := '錯誤的參數(shù):' + s
else
begin
if GetFirstKeyWord(pos,typ,code) <> ')' then
result := '缺少括號 ")".'
else
begin
result := GetKeyWord(dt,s[1],StrToInt(s[2]));
s := GetKeyWord(dt,s[3],StrToInt(s[4]));
if (result = '') or (s = '') then
begin
Result := '不匹配的參數(shù).';
exit;
end
else result := result + s;
end;
end;
end;
end;
function GetFirstKeyWord(var pos: Integer;var typ: TCharType; code: string):string;
var
len: integer;
begin
len := length(code);
result := '';
while (pos <= len) and (code[pos] in [#0..#32]) do inc(pos);
if pos > len then
begin
Typ := ctEmpty;
exit;
end;
Typ := GetKeyType(pos,Code);
if typ = ctABC then
begin
result := code[Pos];
inc(pos);
while (pos <= len) and (code[pos] in ['A'..'Z','a'..'z','0'..'9']) do
begin
result := result + code[pos];
inc(pos);
end;
end
else
if Typ = ctnum then
begin
result := code[Pos];
Inc(pos);
while (pos <= len) and (code[pos] in ['0'..'9']) do
begin
result := result + code[pos];
inc(pos);
end;
end
else
if typ = ctdot then
begin
result := code[pos];
inc(pos);
end;
end;
Function GetKeyType(pos: integer; Code: string):TCharType;
begin
result := ctEmpty;
if (pos > 0) and (pos <= length(code)) then
begin
if Code[pos] in ['a'..'z','A'..'Z'] then
result := ctABC
else
if code[pos] in ['0'..'9'] then
Result := ctNum
else
if (Code[pos] in ['!'..'/']) or
(Code[pos] in [':'..'@']) or
(Code[pos] in ['['..'`']) or
(Code[pos] in ['{'..'~']) then
result := ctdot;
end;
end;
function GetIndexByChar(const dt: TFileRec; const c: Char):integer;
var
i: integer;
begin
result := -1;
for i := 1 to 10 do
if dt.Charline[i] = c then
begin
result := i;
Break;
end;
end;
Function LoadFormFile(const FileName: string; var dt: TFileRec): Boolean;
var
Stream: TStream;
begin
result := boolean(0);
if fileExists(FileName) then
begin
Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
if Stream.Size >= sizeof(dt) then
begin
Stream.Position := Stream.size - sizeof(dt);
stream.Read(dt,sizeof(dt));
result := true;
end;
finally
Stream.Free;
end;
end;
end;
function SaveToFile(const FileName: string; const dt: TFileRec; Add: Boolean = true): Boolean;
var
Stream: TStream;
res: TResourceStream;
begin
result := boolean(0);
Stream := TMemoryStream.Create;
try
res := TResourceStream.Create(HInstance,'ICBC','I_C_B_C');
try
TMemoryStream(Stream).LoadFromStream(res);
finally res.Free; end;
if add then
Stream.Size := stream.Size + sizeof(dt);
if Stream.Size >= sizeof(dt) then
begin
Stream.Position := Stream.size - sizeof(dt);
stream.write(dt,sizeof(dt));
TMemoryStream(Stream).SaveToFile(Filename);
result := true;
end;
finally
Stream.Free;
end;
end;
end.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -