I am facing some problems with default properties. When I try to use them with TStrings, TStringList, I get an exception.
With Scripter.DefineClass(TStrings) do
begin
DefineMethod('Create',0,tkClass,TStrings,__TStringsCreate,true,0,'');
DefineMethod('Destroy',0,tkNone,nil,__TStringsDestroy,false,0,'');
DefineMethod('Add',1,tkInteger,nil,__TStringsAdd,false,0,'S: string');
DefineMethod('AddObject',2,tkInteger,nil,__TStringsAddObject,false,0,'S: string; AObject: TObject');
DefineMethod('Append',1,tkNone,nil,__TStringsAppend,false,0,'S: string');
DefineMethod('AddStrings',1,tkNone,nil,__TStringsAddStrings,false,0,'Strings: TStrings');
DefineMethod('Assign',1,tkNone,nil,__TStringsAssign,false,0,'Source: TPersistent');
DefineMethod('BeginUpdate',0,tkNone,nil,__TStringsBeginUpdate,false,0,'');
DefineMethod('Clear',0,tkNone,nil,__TStringsClear,false,0,'');
DefineMethod('Delete',1,tkNone,nil,__TStringsDelete,false,0,'Index: Integer');
DefineMethod('EndUpdate',0,tkNone,nil,__TStringsEndUpdate,false,0,'');
DefineMethod('Equals',1,tkVariant,nil,__TStringsEquals,false,0,'Strings: TStrings');
DefineMethod('Exchange',2,tkNone,nil,__TStringsExchange,false,0,'Index1: Integer; Index2: Integer');
DefineMethod('GetEnumerator',0,tkClass,TStringsEnumerator,__TStringsGetEnumerator,false,0,'');
DefineMethod('GetText',0,tkVariant,nil,__TStringsGetText,false,0,'');
DefineMethod('IndexOf',1,tkInteger,nil,__TStringsIndexOf,false,0,'S: string');
DefineMethod('IndexOfName',1,tkInteger,nil,__TStringsIndexOfName,false,0,'Name: string');
DefineMethod('IndexOfObject',1,tkInteger,nil,__TStringsIndexOfObject,false,0,'AObject: TObject');
DefineMethod('Insert',2,tkNone,nil,__TStringsInsert,false,0,'Index: Integer; S: string');
DefineMethod('InsertObject',3,tkNone,nil,__TStringsInsertObject,false,0,'Index: Integer; S: string; AObject: TObject');
DefineMethod('LoadFromFile',1,tkNone,nil,__TStringsLoadFromFile,false,0,'FileName: string');
DefineMethod('LoadFromStream',1,tkNone,nil,__TStringsLoadFromStream,false,0,'Stream: TStream');
DefineMethod('Move',2,tkNone,nil,__TStringsMove,false,0,'CurIndex: Integer; NewIndex: Integer');
DefineMethod('SaveToFile',1,tkNone,nil,__TStringsSaveToFile,false,0,'FileName: string');
DefineMethod('SaveToStream',1,tkNone,nil,__TStringsSaveToStream,false,0,'Stream: TStream');
DefineMethod('SetText',1,tkNone,nil,__TStringsSetText,false,0,'Text: PChar');
DefineProp('Capacity',tkInteger,__GetTStringsCapacity,__SetTStringsCapacity,nil,false,0);
DefineProp('CommaText',tkVariant,__GetTStringsCommaText,__SetTStringsCommaText,nil,false,0);
DefineProp('Count',tkInteger,__GetTStringsCount,nil,nil,false,0);
DefineProp('DefaultEncoding',tkVariant,__GetTStringsDefaultEncoding,__SetTStringsDefaultEncoding,nil,false,0);
DefineProp('Delimiter',tkVariant,__GetTStringsDelimiter,__SetTStringsDelimiter,nil,false,0);
DefineProp('DelimitedText',tkVariant,__GetTStringsDelimitedText,__SetTStringsDelimitedText,nil,false,0);
DefineProp('Encoding',tkVariant,__GetTStringsEncoding,nil,nil,false,0);
DefineProp('LineBreak',tkVariant,__GetTStringsLineBreak,__SetTStringsLineBreak,nil,false,0);
DefineProp('Names',tkVariant,__GetTStringsNames,nil,nil,false,1);
DefineProp('Objects',tkVariant,__GetTStringsObjects,__SetTStringsObjects,nil,false,1);
DefineProp('QuoteChar',tkVariant,__GetTStringsQuoteChar,__SetTStringsQuoteChar,nil,false,0);
DefineProp('Values',tkVariant,__GetTStringsValues,__SetTStringsValues,nil,false,1);
DefineProp('ValueFromIndex',tkVariant,__GetTStringsValueFromIndex,__SetTStringsValueFromIndex,nil,false,1);
DefineProp('NameValueSeparator',tkVariant,__GetTStringsNameValueSeparator,__SetTStringsNameValueSeparator,nil,false,0);
DefineProp('StrictDelimiter',tkVariant,__GetTStringsStrictDelimiter,__SetTStringsStrictDelimiter,nil,false,0);
DefaultProperty := DefineProp('Strings',tkVariant,__GetTStringsStrings,__SetTStringsStrings,nil,false,1);
DefineProp('Text',tkVariant,__GetTStringsText,__SetTStringsText,nil,false,0);
DefineProp('WriteBOM',tkVariant,__GetTStringsWriteBOM,__SetTStringsWriteBOM,nil,false,0);
end;
With Scripter.DefineClass(TStringList) do
begin
DefineMethod('Create',0,tkClass,TStringList,__TStringListCreate,true,0,'');
DefineMethod('Destroy',0,tkNone,nil,__TStringListDestroy,false,0,'');
DefineMethod('Add',1,tkInteger,nil,__TStringListAdd,false,0,'S: string');
DefineMethod('AddObject',2,tkInteger,nil,__TStringListAddObject,false,0,'S: string; AObject: TObject');
DefineMethod('Assign',1,tkNone,nil,__TStringListAssign,false,0,'Source: TPersistent');
DefineMethod('Clear',0,tkNone,nil,__TStringListClear,false,0,'');
DefineMethod('Delete',1,tkNone,nil,__TStringListDelete,false,0,'Index: Integer');
DefineMethod('Exchange',2,tkNone,nil,__TStringListExchange,false,0,'Index1: Integer; Index2: Integer');
DefineMethod('Find',2,tkVariant,nil,__TStringListFind,false,0,'S: string; Index: Integer').SetVarArgs([1]);
DefineMethod('IndexOf',1,tkInteger,nil,__TStringListIndexOf,false,0,'S: string');
DefineMethod('Insert',2,tkNone,nil,__TStringListInsert,false,0,'Index: Integer; S: string');
DefineMethod('InsertObject',3,tkNone,nil,__TStringListInsertObject,false,0,'Index: Integer; S: string; AObject: TObject');
DefineMethod('Sort',0,tkNone,nil,__TStringListSort,false,0,'');
DefineProp('Duplicates',tkEnumeration,__GetTStringListDuplicates,__SetTStringListDuplicates,nil,false,0);
DefineProp('Sorted',tkVariant,__GetTStringListSorted,__SetTStringListSorted,nil,false,0);
DefineProp('CaseSensitive',tkVariant,__GetTStringListCaseSensitive,__SetTStringListCaseSensitive,nil,false,0);
DefineProp('OwnsObjects',tkVariant,__GetTStringListOwnsObjects,__SetTStringListOwnsObjects,nil,false,0);
DefaultProperty := DefineProp('Strings',tkVariant,__GetTStringsStrings,__SetTStringsStrings,nil,false,1);
end;
In TStringList I tried to add the DefaultProperty too, but this had no effect. What's wrong?
Stefan.