以下代码经本人在Delphi XE2 下编写并通过。
function Matching(Code,MName,Temp,Source: string) : string; var qryQuery : TADOQuery; sql,Balance,SouStr : string; reg: TPerlRegEx; begin reg := TPerlRegEx.Create; qryQuery := Tadoquery.Create(Application); qryQuery.Connection := Form1.con1; sql := 'select * from CustomerInfo where CardsName1='''+Code+''''; qryQuery.Close; qryQuery.SQL.Clear; qryQuery.SQL.Add(sql); qryQuery.Open; if qryQuery.RecordCount > 0 then begin Balance := qryQuery.FieldByName('Balance').AsString; end else Balance := ''; //会员编号 reg.Subject := Source; reg.RegEx := '@'; reg.Replacement := Code; reg.ReplaceAll; SouStr := reg.Subject; //会员姓名 reg.Subject := SouStr; reg.RegEx := '-'; reg.Replacement := MName; reg.ReplaceAll; SouStr := reg.Subject; //会员金额 reg.Subject := SouStr; reg.RegEx := '&'; reg.Replacement := Temp; reg.ReplaceAll; SouStr := reg.Subject; //会员余款 reg.Subject := SouStr; reg.RegEx := '#'; reg.Replacement := Balance; reg.ReplaceAll; SouStr := reg.Subject; Result := SouStr; FreeAndNil(reg); qryQuery.Free; end;