📄 smsdll.pas
字号:
unit smsdll;
interface
uses inifiles,loginform,sysutils,classes,smsform;
type
user=record
name:string;
sex:boolean;
phone:string;
memo:string;
end;
type userinfomation=record
name:string;
phone:string;
password:string;
end;
var
usercount:integer;
userinfo:array[0..100] of userinfomation;
curuser:userinfomation;
ini,userini: tinifile;
userlist:array[0..100] of user;
function passwordstring(pswd:string):string;
function readfromfile(ff:string):tstringlist;
procedure updatesg(ff:string);
procedure updatephone;
procedure readini;
procedure readuserini;
function writeuserini(name,phone,password:string):integer;
function writeini(name:string;sex:boolean;phone:string;memo:string):integer;
function deleteini(name:string;phone:string):integer;
implementation
procedure readuserini;
var
i:integer;
k:string;
begin
count:=userini.ReadInteger('count','count',0);
loginfrm.comusername.items.Clear;
for i:=1 to count do
begin
k:='user'+inttostr(i);
userinfo[i-1].name := userini.ReadString(k,'name','');
userinfo[i-1].phone :=userini.ReadString(k,'phone','');
userinfo[i-1].password :=passwordstring(userini.ReadString(k,'password',''));
loginfrm.comusername.Items.Add(userinfo[i-1].name);
end;
end;
function writeuserini(name,phone,password:string):integer;
var
i,j:integer;
b:boolean;
k:string;
begin
j:=count;
b:=true;
for i:=1 to j do
begin
if (name=userinfo[i-1].name)and(phone=userinfo[i-1].phone) then
begin
b:=false;
break;
end;
end;
if (i<=0)or(i>(j+1)) then
i:=1;
if b then inc(j);
k:='user'+inttostr(i);
userini.WriteString(k,'name',(name));
userini.WriteString(k,'phone',(phone));
userini.WriteString(k,'password',passwordstring(password));
userini.WriteInteger('count','count',j);
result:=j;
end;
procedure updatephone;
var
i:integer;
begin
with smsfrm do
begin
sg2.RowCount :=2;
for i:=0 to 4 do
sg2.Cells[i,1]:='';
myphonebook.Items.Clear;
end;
for i:=1 to usercount do
begin
with smsfrm do
begin
if i>1 then sg2.RowCount :=sg2.RowCount +1;
myphonebook.Items.Add(userlist[i-1].name);
sg2.Cells[0,i]:=inttostr(i);
sg2.Cells[1,i]:=userlist[i-1].name;
if userlist[i-1].sex then
sg2.Cells[2,i]:='男'
else
sg2.cells[2,i]:='女';
sg2.Cells[3,i]:=userlist[i-1].phone ;
sg2.Cells[4,i]:=userlist[i-1].memo;
end;
end;
smsfrm.myphonebook.ItemIndex :=-1;
end;
function passwordstring(pswd:string):string;
var
i,j:integer;
key:byte;
begin
key:=16;
j:=length(pswd);
result:='';
for i:=1 to j do
begin
result:=result+char(ord(pswd[i]) xor key);
end;
end;
procedure readini;
var
i:integer;
k:string;
begin
usercount:=ini.ReadInteger('count','usercount',0);
for i:=1 to usercount do
begin
k:='user'+inttostr(i);
userlist[i-1].name :=passwordstring(ini.ReadString(k,'name',''));
userlist[i-1].sex :=ini.ReadBool(k,'sex',true);
userlist[i-1].phone :=passwordstring(ini.ReadString(k,'phone',''));
userlist[i-1].memo :=ini.ReadString(k,'memo','');
end;
end;
function writeini(name:string;sex:boolean;phone:string;memo:string):integer;
var
i,j:integer;
b:boolean;
k:string;
begin
j:=ini.ReadInteger('count','usercount',0);
b:=true;
for i:=1 to j do
begin
if (name=userlist[i-1].name)and(phone=userlist[i-1].phone) then
begin
b:=false;
break;
end;
end;
if (i<=0)or(i>(j+1)) then
i:=1;
if b then inc(j);
k:='user'+inttostr(i);
ini.WriteString(k,'name',passwordstring(name));
ini.WriteBool(k,'sex',sex);
ini.WriteString(k,'phone',passwordstring(phone));
ini.WriteString(k,'memo',memo);
ini.WriteInteger('count','usercount',j);
result:=j;
end;
function deleteini(name:string;phone:string):integer;
var
i,i1,j:integer;
b:boolean;
k:string;
begin
j:=ini.ReadInteger('count','usercount',0);
if j=0 then
begin
result:=0;
exit;
end;
b:=false;
for i:=1 to j do
begin
if (name=userlist[i-1].name)and(phone=userlist[i-1].phone) then
begin
b:=true;
break;
end;
end;
if b then
begin
for i1:=i+1 to j do
begin
k:='user'+inttostr(i1);
ini.WriteString('user'+inttostr(i1-1),'name',ini.ReadString(k,'name',''));
ini.Writebool('user'+inttostr(i1-1),'sex',ini.Readbool(k,'sex',true));
ini.WriteString('user'+inttostr(i1-1),'phone',ini.ReadString(k,'phone',''));
ini.WriteString('user'+inttostr(i1-1),'memo',ini.ReadString(k,'memo',''));
end;
k:='user'+inttostr(j);
ini.DeleteKey(k,'name');
ini.DeleteKey(k,'sex');
ini.DeleteKey(k,'phone');
ini.DeleteKey(k,'memo');
j:=j-1;
end;
ini.WriteInteger('count','usercount',j);
result:=j;
end;
procedure updatesg(ff:string);
var
st:tstringlist;
i,j:integer;
m,n,k,p:integer;
s:string;
begin
st:=readfromfile(ff);
with smsfrm do
begin
sg.RowCount :=2;
sg.Cells[0,1]:='';
sg.Cells[1,1]:='';
sg.Cells[2,1]:='';
j:=st.Count;
for i:=0 to j-1 do
begin
if i>0 then sg.RowCount :=sg.RowCount +1;
s:=st.Strings[i];
for m:=1 to length(s) do
if s[m]<>' ' then break;
if m>0 then
s:=copy(s,m,length(s)-m+1);
m:=pos(' ',s);
sg.Cells[0,i+1]:=copy(s,1,m-1);
////////////////////////////////
for n:=m to length(s) do
if s[n]<>' ' then break;
k:=n;
for m:=length(s) downto n do
if s[m]<>' ' then break;
n:=m;
//s:=copy(s,k,m-k+1);
//s的内容为从k到n的长度
for p:=n downto k do
if s[p]=' ' then
break;
sg.Cells[2,i+1]:=copy(s,p+1,n-p);
for n:=p downto k do
if s[n]<>' ' then break;
sg.Cells[1,i+1]:=copy(s,k,n-k+1);
end;
end;
end;
function readfromfile(ff:string):tstringlist;
var
f:textfile;
sl:tstringlist;
s:string;
begin
assignfile(f,ff);
reset(f);
sl:=tstringlist.Create;
while not eof(f) do
begin
readln(f,s);
sl.Add(s);
end;
result:=sl;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -