?? publicfunction.~pa
字號:
Inc(Group);
if (Group = 3) and Thousands and (I > MinSym) then begin
Group := 0;
Result := ThousandSeparator + Result;
end;
end;
if IsSign then Result := S[1] + Result;
if Result = '0' then Result := '';
end;
function NumClear(Num: string): string; //去掉數字中的','等
var
i: integer;
NumChr: string;
NumStr: string;
begin
if num = '' then num := '0';
for i := 1 to length(num) do
begin
NumChr := copy(num, i, 1);
if (NumChr = '0') or (NumChr = '1') or (NumChr = '2') or
(NumChr = '3') or (NumChr = '4') or (NumChr = '5') or (NumChr = '6')
or (NumChr = '7') or (NumChr = '8') or (NumChr = '9') or (NumChr = '.') or (NumChr = '-') then
numstr := numstr + numchr;
end;
if numstr = '' then numstr := '0';
// Result := strtofloat(numstr);
result := numstr;
end;
procedure deleteRec(var Connection: TADOConnection; TableName, Condition: string);
var
Query1: TADOQuery;
begin
Query1 := TADOQuery.Create(nil);
try
with Query1 do begin
Connection := StockDM.ADOConnBarCodeTemp; //Connection;
SQL.Clear;
if Condition <> '' then
SQL.Add('delete from' + TableName + ' where ' + Condition)
else
SQL.Add('delete from ' + TableName);
ExecSQL;
Close;
end;
finally
Query1.Free;
end;
end;
function checkFilename(tempchar: string; SourceStr: string): string; //去掉filemae中的s除去空格
var
temp, stemp: string;
i: integer;
begin
temp := '';
for i := 0 to Length(SourceStr) do
begin
stemp := copy(SourceStr, i + 1, 1);
if (stemp <> tempchar) then
temp := temp + stemp;
end;
result := temp;
end;
//讀文件,存儲文件到blob
function blobcontenttostring(const fileName: string; ADOTable1: TDataSet; FiledName: string): bool;
var
AStream: TmemoryStream;
begin
//result:=Tmemorystream.Create ;
AStream := TmemoryStream.Create;
AStream.LoadFromFile(fileName);
if AStream.Size <= 0 then begin Result := false; Abort; end;
if not (ADOTable1.State in [dsinsert, dsedit]) then ADOTable1.edit;
try
with ADOTable1.FieldByName(FiledName) as TBlobField do
begin
Astream.Position := 0;
LoadFromStream(Astream);
end;
result := true;
finally
//ADOTable1.post;
AStream.Position := 0;
//AStream.ReadBuffer(result,Astream.Size-1);
AStream.Free;
end;
end;
//存儲文件到blob
//將blob讀到tstream
function GetBlobFileToStream(ADOTable1: TAdoQuery; Name: string): TStream;
var
AFiled: Tfield;
begin
Afiled := Tfield.Create(nil);
AFiled.FieldAddress(Name);
AFiled.DataSet := ADOTable1;
result := ADOtable1.CreateBlobStream(AFiled, bmRead);
end;
//將blob讀到tstream
function GetBlobToStream(Table: TDataSet; const FieldName: string; var ResultStream: TmemoryStream): Bool;
begin
result := false;
try
with Table.FieldByName(FieldName) as TBlobField do
begin
SaveToStream(ResultStream); //把 tempmemorystream的數據寫入 Memorystream當前位置 SaveToStream將自動移動指針等于append
if ResultStream.Size > 0 then
result := true;
end;
finally
//ms.Free;
end;
end;
//返回下一個ID取最大值
function GetNextRecNoMax(ADOConnection: TADOConnection; TableName, Fieldstr, Condition, DesFieldstr: string; FieldLen: integer): longint;
var
lMax: Integer;
lDef: string;
begin
lDef := '000000000000000';
SetLength(lDef, FieldLen - 1);
with TadoQuery.Create(nil) do
try //---- 自動加入編號
begin
Connection := ADOConnection;
SQL.Clear;
SQL.Add('Select max(' + Fieldstr + ') as maxCount from ' + TableName);
Open; //first
if not Eof then //if0 如果此時已到末記錄,證明Query1為空
begin
lMax := FieldByName('maxCount').AsInteger;
end
else
lMax := 0; //end_if0 end_else0,已到末記錄(Query1為空)直接增一
Close;
end; //end_with
Result := lMax + 1; //最小為1
finally
Free;
end;
end;
//---------------------------------------------------------
//connect with database.
function connect_DB(ADO: TADOConnection; ConnStr: string): bool;
begin
try
if ADO.Connected then
begin
ADO.Close;
end;
ADO.ConnectionString := ConnStr;
ADO.Open;
result := true;
except
begin
MessageDlg('數據庫連接失敗', mtWarning, [mbYes], 0);
result := false;
exit;
end;
end;
end;
//得到Achar以后的所有值
function GetIDFromChar(ASecStr: string; Achar: string): string;
var
i: integer;
begin
i := pos(Achar, ASecStr);
//showmessage(inttostr(length(achar))); only for test.
//showmessage(inttostr(i));
result := copy(ASecStr, i + 1, Length(ASecStr) - i - 1);
//showmessage(result);
end;
function FormCenter(AForm: TForm): bool;
begin
AForm.Top := (screen.Height - AForm.Height) div 2;
AForm.Left := (screen.Width - AForm.Width) div 2;
end;
function GetPYIndexChar(hzchar: string): char;
begin
case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of
$B0A1..$B0C4: result := 'A';
$B0C5..$B2C0: result := 'B';
$B2C1..$B4ED: result := 'C';
$B4EE..$B6E9: result := 'D';
$B6EA..$B7A1: result := 'E';
$B7A2..$B8C0: result := 'F';
$B8C1..$B9FD: result := 'G';
$B9FE..$BBF6: result := 'H';
$BBF7..$BFA5: result := 'J';
$BFA6..$C0AB: result := 'K';
$C0AC..$C2E7: result := 'L';
$C2E8..$C4C2: result := 'M';
$C4C3..$C5B5: result := 'N';
$C5B6..$C5BD: result := 'O';
$C5BE..$C6D9: result := 'P';
$C6DA..$C8BA: result := 'Q';
$C8BB..$C8F5: result := 'R';
$C8F6..$CBF9: result := 'S';
$CBFA..$CDD9: result := 'T';
$CDDA..$CEF3: result := 'W';
$CEF4..$D188: result := 'X';
$D1B9..$D4D0: result := 'Y';
$D4D1..$D7F9: result := 'Z';
else
result := char(0);
end;
end;
//前導去零
function RemoveFrontZeroFromStr(sec: string): string;
var
i: integer;
begin
for i := 1 to length(sec) do
begin
if sec[i] = '0' then continue;
if sec[i] <> '0' then result := copy(sec, i, length(sec) - i + 1); exit;
end;
end;
function selectDB(Aform: TForm): string;
var
DBLinkStr: string;
begin
DBLinkStr := PromptDataSource(Aform.Handle, dblinkstr);
result := DBLinkStr;
end;
//get the value from ini file.
function GetCfgValue(const key: string; cfgFileName: string): string;
var
cfn: string;
ini: tinifile;
begin
Result := '';
cfn := ExtractFilePath(Application.ExeName) + cfgFileName;
if FileExists(cfn) then
begin
ini := tinifile.Create(cfn);
try
Result := ini.ReadString('Options', key, Result);
finally
ini.Free;
end;
end;
end;
function SetCfgValue(const key: string; Value: string; cfgFileName: string): bool;
var
cfn: string;
ini: tinifile;
begin
result := true;
cfn := ExtractFilePath(Application.ExeName) + cfgFileName;
if FileExists(cfn) then
begin
ini := tinifile.Create(cfn);
try
ini.WriteString('Options', key, value);
finally
ini.Free;
end;
end;
end;
function GetValueTostr(ATable: string; AFile: string; AFlagField: string; Avalue: string): string;
var
test: string;
begin
// With TAdoQuery.Create(nil) do
result := '';
with TAdoQuery.Create(nil) do
begin
try
connection := stockDM.ADOConn;
Sql.Clear;
if Avalue = 'All' then
begin
test := 'SELECT * FROM ' + ATable + '';
end
else
begin
test := 'SELECT ' + AFile + ' FROM ' + ATable + ' where ' + AFlagField + '='#39 + Avalue + #39'';
end;
sql.Text := test;
open;
if not Isempty then
begin
result := fieldbyname(AFile).AsString;
end
else
begin
result := '';
end;
finally
Free;
end;
end;
end;
//check the valu if exits in a table. exit =true ,else =false
function checkValue(ATable: string; AFile: string; Avalue: string): bool;
var
test: string;
begin
// With TAdoQuery.Create(nil) do
with TAdoQuery.Create(nil) do
begin
try
connection := StockDM.ADOConn;
Sql.Clear;
//henry2007321
//test:='SELECT * FROM '+ATable+' where '+AFile+'='#39 + Avalue +#39'';
test := 'SELECT ' + AFile + ' FROM ' + ATable + ' where ' + AFile + '='#39 + Avalue + #39'';
sql.Text := test;
open;
if not Isempty then
begin
result := true;
end
else
result := false;
finally
Free;
end;
end;
end;
//check values
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -