Author: Jonas Bilinkevicius
Using D6 I need to extract the Word version on the client computer. The options are
Word97, Word2000 and WordXP.
Answer:
1 function GetCurrentWordMajorVersion: Integer;
2 var3 vRegistry: TRegistry;
4 vVersionStr: string;
5 vVersion: string;
6 begin7 Result := -1;
8 vRegistry := TRegistry.Create(KEY_READ);
9 try10 vRegistry.RootKey := HKEY_CLASSES_ROOT;
11 if vRegistry.OpenKeyReadOnly('Word.Application\CurVer') then12 begin13 {Get the default value: 'Word.Application.10'}14 vVersionStr := vRegistry.ReadString('');
15 {Extract the major version from the string}16 vVersion := System.Copy(vVersionStr, Succ(LastDelimiter('.', vVersionStr)),
17 MAXINT);
18 {8=Word97, 9=Word2000, 10=Word2002, etc.}19 Result := StrToIntDef(vVersion, -1);
20 end;
21 finally22 vRegistry.Free;
23 end;
24 end;