|
@@ -53,7 +53,7 @@ To load a different type of library resource, append an integer index to 'FileNa
|
|
Example: C:\WINDOWS\system32\msvbvm60.dll\3
|
|
Example: C:\WINDOWS\system32\msvbvm60.dll\3
|
|
}
|
|
}
|
|
function ImportTypelib(FileName: WideString;var sUnitName:string;var slDependencies:TStringList;
|
|
function ImportTypelib(FileName: WideString;var sUnitName:string;var slDependencies:TStringList;
|
|
- bActiveX,bPackage:boolean;var sPackageSource,sPackageRegUnitSource:String):string;
|
|
|
|
|
|
+ bActiveX,bPackage,bRemoveStructTag:boolean;var sPackageSource,sPackageRegUnitSource:String):string;
|
|
|
|
|
|
|
|
|
|
Type
|
|
Type
|
|
@@ -66,6 +66,7 @@ Type
|
|
FAppendVersionNumber: Boolean;
|
|
FAppendVersionNumber: Boolean;
|
|
FCreatePackage: Boolean;
|
|
FCreatePackage: Boolean;
|
|
FDependencies: TStringList;
|
|
FDependencies: TStringList;
|
|
|
|
+ FRemoveStructTag: Boolean;
|
|
FUnitSource: TStringList;
|
|
FUnitSource: TStringList;
|
|
FPackageSource: TStringList;
|
|
FPackageSource: TStringList;
|
|
FPackageRegUnitSource: TStringList;
|
|
FPackageRegUnitSource: TStringList;
|
|
@@ -93,6 +94,7 @@ Type
|
|
procedure SetActiveX(AValue: Boolean);
|
|
procedure SetActiveX(AValue: Boolean);
|
|
procedure SetCreatePackage(AValue: Boolean);
|
|
procedure SetCreatePackage(AValue: Boolean);
|
|
procedure SetOutputFileName(AValue: String);
|
|
procedure SetOutputFileName(AValue: String);
|
|
|
|
+ procedure SetRemoveStructTag(AValue: Boolean);
|
|
procedure SetUnitName(AValue: string);
|
|
procedure SetUnitName(AValue: string);
|
|
Protected
|
|
Protected
|
|
bIsCustomAutomatable,bIsInterface,bIsAutomatable,bIsExternalDecl,bIsUserDefined:boolean;
|
|
bIsCustomAutomatable,bIsInterface,bIsAutomatable,bIsExternalDecl,bIsUserDefined:boolean;
|
|
@@ -116,6 +118,7 @@ Type
|
|
function ValidateIDAgainstDeclared(id: string): boolean; virtual;
|
|
function ValidateIDAgainstDeclared(id: string): boolean; virtual;
|
|
function MakeValidId(id:string;var valid:string): boolean; virtual;
|
|
function MakeValidId(id:string;var valid:string): boolean; virtual;
|
|
function MakeValidIdAgainstDeclared(id:string;var valid:string): boolean;
|
|
function MakeValidIdAgainstDeclared(id:string;var valid:string): boolean;
|
|
|
|
+ function RemoveTag(typename: string): string;
|
|
// The actual routines that do the work.
|
|
// The actual routines that do the work.
|
|
procedure CreateCoClasses(const TL: ITypeLib; TICount: Integer); virtual;
|
|
procedure CreateCoClasses(const TL: ITypeLib; TICount: Integer); virtual;
|
|
procedure CreateForwards(const TL: ITypeLib; TICount: Integer); virtual;
|
|
procedure CreateForwards(const TL: ITypeLib; TICount: Integer); virtual;
|
|
@@ -145,11 +148,13 @@ Type
|
|
// Append version number to unit name.
|
|
// Append version number to unit name.
|
|
Property AppendVersionNumber : Boolean Read FAppendVersionNumber Write FAppendVersionNumber Default True;
|
|
Property AppendVersionNumber : Boolean Read FAppendVersionNumber Write FAppendVersionNumber Default True;
|
|
// Create lpk package for ActiveXContainer descendant: default false
|
|
// Create lpk package for ActiveXContainer descendant: default false
|
|
- Property CreatePackage : Boolean Read FCreatePackage write SetCreatePackage Default False;
|
|
|
|
|
|
+ Property CreatePackage : Boolean read FCreatePackage write SetCreatePackage Default False;
|
|
// File to read typelib from.
|
|
// File to read typelib from.
|
|
Property InputFileName : WideString Read FInputFileName Write FInputFileName;
|
|
Property InputFileName : WideString Read FInputFileName Write FInputFileName;
|
|
// If set, unit source will be written to this file.
|
|
// If set, unit source will be written to this file.
|
|
Property OutputFileName : String Read FOutputFileName Write SetOutputFileName;
|
|
Property OutputFileName : String Read FOutputFileName Write SetOutputFileName;
|
|
|
|
+ // Remove tag from struct names
|
|
|
|
+ Property RemoveStructTag : Boolean read FRemoveStructTag write SetRemoveStructTag Default False;
|
|
// Set automatically by OutputFileName or by Execute
|
|
// Set automatically by OutputFileName or by Execute
|
|
Property UnitName : string Read FUnitname Write SetUnitName;
|
|
Property UnitName : string Read FUnitname Write SetUnitName;
|
|
end;
|
|
end;
|
|
@@ -161,7 +166,7 @@ Resourcestring
|
|
SErrInvalidUnitName = 'Invalid unit name : %s';
|
|
SErrInvalidUnitName = 'Invalid unit name : %s';
|
|
|
|
|
|
function ImportTypelib(FileName: WideString;var sUnitName:string;var slDependencies:TStringList;
|
|
function ImportTypelib(FileName: WideString;var sUnitName:string;var slDependencies:TStringList;
|
|
- bActiveX,bPackage:boolean;var sPackageSource,sPackageRegUnitSource:String):string;
|
|
|
|
|
|
+ bActiveX,bPackage,bRemoveStructTag:boolean;var sPackageSource,sPackageRegUnitSource:String):string;
|
|
var i:integer;
|
|
var i:integer;
|
|
begin
|
|
begin
|
|
With TTypeLibImporter.Create(Nil) do
|
|
With TTypeLibImporter.Create(Nil) do
|
|
@@ -169,6 +174,7 @@ begin
|
|
InputFileName:=FileName;
|
|
InputFileName:=FileName;
|
|
ActiveX:=bActiveX;
|
|
ActiveX:=bActiveX;
|
|
CreatePackage:=bPackage;
|
|
CreatePackage:=bPackage;
|
|
|
|
+ RemoveStructTag:=bRemoveStructTag;
|
|
Execute;
|
|
Execute;
|
|
Result:=UnitSource.Text;
|
|
Result:=UnitSource.Text;
|
|
sUnitname:=UnitName;
|
|
sUnitname:=UnitName;
|
|
@@ -301,6 +307,18 @@ begin
|
|
MakeValidIdAgainstDeclared(id+'_',valid);
|
|
MakeValidIdAgainstDeclared(id+'_',valid);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TTypeLibImporter.RemoveTag(typename: string): string;
|
|
|
|
+begin
|
|
|
|
+ result:=typename;
|
|
|
|
+ if FRemoveStructTag and (pos('tag',typename)>0) then
|
|
|
|
+ if (copy(typename,1,3)='tag') then
|
|
|
|
+ delete(result,1,3)
|
|
|
|
+ else if (copy(typename,1,4)='_tag') then
|
|
|
|
+ delete(result,2,3)
|
|
|
|
+ else if (copy(typename,1,5)='__tag') then
|
|
|
|
+ delete(result,3,3);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
|
|
function TTypeLibImporter.TypeToString(TI:ITypeInfo; TD:TYPEDESC):string;
|
|
function TTypeLibImporter.TypeToString(TI:ITypeInfo; TD:TYPEDESC):string;
|
|
|
|
|
|
@@ -331,9 +349,11 @@ begin
|
|
TD:=TD.lptdesc^;
|
|
TD:=TD.lptdesc^;
|
|
OleCheck(TI.GetRefTypeInfo(TD.hreftype,TIref));
|
|
OleCheck(TI.GetRefTypeInfo(TD.hreftype,TIref));
|
|
OleCheck(TIRef.GetDocumentation(DISPID_UNKNOWN, @BstrName, nil, nil, nil));
|
|
OleCheck(TIRef.GetDocumentation(DISPID_UNKNOWN, @BstrName, nil, nil, nil));
|
|
- MakeValidId(BstrName,result);
|
|
|
|
OleCheck(TIRef.GetTypeAttr(TARef));
|
|
OleCheck(TIRef.GetTypeAttr(TARef));
|
|
bIsCustomAutomatable:=TARef^.typekind in [TKIND_DISPATCH,TKIND_INTERFACE,TKIND_ENUM,TKIND_COCLASS];
|
|
bIsCustomAutomatable:=TARef^.typekind in [TKIND_DISPATCH,TKIND_INTERFACE,TKIND_ENUM,TKIND_COCLASS];
|
|
|
|
+ if TARef^.typekind in [TKIND_RECORD,TKIND_UNION,TKIND_ALIAS] then
|
|
|
|
+ BstrName:=RemoveTag(BstrName);
|
|
|
|
+ MakeValidId(BstrName,result);
|
|
if TARef^.typekind=TKIND_ALIAS then
|
|
if TARef^.typekind=TKIND_ALIAS then
|
|
begin
|
|
begin
|
|
TypeToString(TIRef,TARef^.tdescAlias); //not interested in result, only bIsCustomAutomatable and bIsInterface
|
|
TypeToString(TIRef,TARef^.tdescAlias); //not interested in result, only bIsCustomAutomatable and bIsInterface
|
|
@@ -1210,7 +1230,7 @@ begin
|
|
case TIT of
|
|
case TIT of
|
|
TKIND_RECORD,TKIND_UNION:
|
|
TKIND_RECORD,TKIND_UNION:
|
|
begin
|
|
begin
|
|
- if not MakeValidId(BstrName,sRecordName) then
|
|
|
|
|
|
+ if not MakeValidId(RemoveTag(BstrName),sRecordName) then
|
|
AddToHeader('// Warning: renamed record ''%s'' to ''%s''',[BstrName,sRecordName],True);
|
|
AddToHeader('// Warning: renamed record ''%s'' to ''%s''',[BstrName,sRecordName],True);
|
|
AddToInterface(' P%s = ^%s;'#13#10,[sRecordName,sRecordName]);
|
|
AddToInterface(' P%s = ^%s;'#13#10,[sRecordName,sRecordName]);
|
|
FTypes.Add('P'+sRecordName);
|
|
FTypes.Add('P'+sRecordName);
|
|
@@ -1260,7 +1280,7 @@ begin
|
|
stype:=TypeToString(TI, TA^.tdescAlias);
|
|
stype:=TypeToString(TI, TA^.tdescAlias);
|
|
if bIsUserDefined and not ValidateID(stype) then
|
|
if bIsUserDefined and not ValidateID(stype) then
|
|
stype:=stype+'_';
|
|
stype:=stype+'_';
|
|
- if not MakeValidId(BstrName,sRecordName) then
|
|
|
|
|
|
+ if not MakeValidId(RemoveTag(BstrName),sRecordName) then
|
|
AddToHeader('// Warning: renamed alias ''%s'' to ''%s''',[BstrName,sRecordName],True);
|
|
AddToHeader('// Warning: renamed alias ''%s'' to ''%s''',[BstrName,sRecordName],True);
|
|
sl:=format(' %s = %s;',[sRecordName,stype]);
|
|
sl:=format(' %s = %s;',[sRecordName,stype]);
|
|
if bIsUserDefined and not bIsExternalDecl and (FTypes.IndexOf(stype)=-1) then //not defined yet, defer
|
|
if bIsUserDefined and not bIsExternalDecl and (FTypes.IndexOf(stype)=-1) then //not defined yet, defer
|
|
@@ -1810,6 +1830,12 @@ begin
|
|
SetUnitName(UN)
|
|
SetUnitName(UN)
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTypeLibImporter.SetRemoveStructTag(AValue: Boolean);
|
|
|
|
+begin
|
|
|
|
+ if FRemoveStructTag=AValue then Exit;
|
|
|
|
+ FRemoveStructTag:=AValue;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTypeLibImporter.SetUnitName(AValue: string);
|
|
procedure TTypeLibImporter.SetUnitName(AValue: string);
|
|
begin
|
|
begin
|
|
if FUnitname=AValue then Exit;
|
|
if FUnitname=AValue then Exit;
|