help!!!copy 函数问题! ( 积分: 100 )

  • 主题发起人 主题发起人 hartlen
  • 开始时间 开始时间
H

hartlen

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
var
Reg : TRegistry;
Val : TStrings;
i : Integer;
InternalPatternVer : integer;
VsApiNTVer : string;
version : string;
begin
InternalPatternVer:=0;
VsApiNTVer:='';
Val:=TStringList.Create;
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
try
if Reg.OpenKey('Software/TrendMicro/PC-cillinNTCorp/CurrentVersion/Misc.',False) then
begin
reg.GetValueNames(val);
if Val.Count>0 then
begin
InternalPatternVer:=0;
VsApiNTVer:='';
for i:=0 to Val.Count-1 do
begin
if Val.Strings='InternalPatternVer' then
begin
InternalPatternVer:=Reg.ReadInteger(Val.Strings);
end;

if Val.Strings='VsApiNT-Ver' then
begin
VsApiNTVer:= Reg.ReadString(Val.Strings);
end;
end;
end;
end;
finally
Reg.Free;
val.Free;
end;

if (VsApiNTVer<>'') and (InternalPatternVer<>0) then
begin
VsApiNTVer:=copy(VsApiNTVer,0,5);
showmessage(inttostr(InternalPatternVer))
[blue]//////显示是 280500[/blue] version:=[red]copy(inttostr(InternalPatternVer),0,1) +'.' +copy(inttostr(InternalPatternVer),1,3)+'.'+ copy(inttostr(InternalPatternVer),5,2)[/red];
showmessage(version)
//显示是2.280.00
end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
Reg : TRegistry;
Val : TStrings;
i : Integer;
InternalPatternVer : integer;
VsApiNTVer : string;
version : string;
begin
InternalPatternVer:=0;
VsApiNTVer:='';
Val:=TStringList.Create;
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
try
if Reg.OpenKey('Software/TrendMicro/PC-cillinNTCorp/CurrentVersion/Misc.',False) then
begin
reg.GetValueNames(val);
if Val.Count>0 then
begin
InternalPatternVer:=0;
VsApiNTVer:='';
for i:=0 to Val.Count-1 do
begin
if Val.Strings='InternalPatternVer' then
begin
InternalPatternVer:=Reg.ReadInteger(Val.Strings);
end;

if Val.Strings='VsApiNT-Ver' then
begin
VsApiNTVer:= Reg.ReadString(Val.Strings);
end;
end;
end;
end;
finally
Reg.Free;
val.Free;
end;

if (VsApiNTVer<>'') and (InternalPatternVer<>0) then
begin
VsApiNTVer:=copy(VsApiNTVer,0,5);
showmessage(inttostr(InternalPatternVer))
[blue]//////显示是 280500[/blue] version:=[red]copy(inttostr(InternalPatternVer),0,1) +'.' +copy(inttostr(InternalPatternVer),1,3)+'.'+ copy(inttostr(InternalPatternVer),5,2)[/red];
showmessage(version)
//显示是2.280.00
end;
end;
 
我自己已经找到错误!谢谢大家
 
version:=copy(inttostr(InternalPatternVer),0,1) +'.' +copy(inttostr(InternalPatternVer),2,3)+'.'+ copy(inttostr(InternalPatternVer),4,2);
 
Delphi里面的字符串是从1开始的,你从0开始Copy当然有问题了。
version:=copy(inttostr(InternalPatternVer),1,1) +'.' +copy(inttostr(InternalPatternVer),2,3)+'.'+ copy(inttostr(InternalPatternVer),5,2);
 
接受答案了.
 
后退
顶部